diff --git a/BPA.KitChen.StoreManagement.Application/BaseDto/DtoValidator.cs b/BPA.KitChen.StoreManagement.Application/BaseDto/DtoValidator.cs new file mode 100644 index 0000000..c851adf --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/BaseDto/DtoValidator.cs @@ -0,0 +1,83 @@ + + +using BPA.KitChen.StoreManagement.Core.Entity; +using BPA.KitChen.StoreManagement.Core.Enum; +using BPA.KitChen.StoreManagement.SqlSugar; +using MySqlConnector; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; + +namespace BPA.KitChen.StoreManagement.Application.BaseDto +{ + /// + /// Dto参数验证 + /// + public class DtoValidator + { + + /// + /// 验证会员 + /// + /// + /// + public static ValidationResult Member(string id) + { + var data = SqlSugarDb.Db.Queryable().First(x => x.Id == id&&x.IsDeleted==0); + return data == null ? new ValidationResult("会员不存在") : ValidationResult.Success; + } + + + /// + /// 验证会员标签的合法性 + /// + /// + /// + public static ValidationResult MemberTag(string id) + { + var data = SqlSugarDb.Db.Queryable().First(x=>x.Id==id); + return data == null ? new ValidationResult("会员标签不存在") : ValidationResult.Success; + } + /// + /// 验证会员标签的合法性 + /// + /// + /// + public static ValidationResult MemberTagList(List ids) + { + var data = SqlSugarDb.Db.Queryable().Where(x => ids.Contains(x.Id) && x.IsDeleted == 0&&x.Status== CommonStatus.ENABLE).ToList(); + return data.Count<=0 ? new ValidationResult("会员标签不存在") : ValidationResult.Success; + } + + /// + /// 会员平台 + /// + /// + /// + public static ValidationResult MemberPlatformType(int type) + { + return !System.Enum.IsDefined(typeof(PlatformType), type) ? new ValidationResult("平台类型不存在") : ValidationResult.Success; + + } + + /// + /// 会员平台 + /// + /// + /// + public static ValidationResult Status(int type) + { + return !System.Enum.IsDefined(typeof(CommonStatus), type) ? new ValidationResult("状态错误") : ValidationResult.Success; + + } + /// + /// 优惠券使用 + /// + /// + /// + public static ValidationResult CouponUseType(int type) + { + return !System.Enum.IsDefined(typeof(CouponUseType), type) ? new ValidationResult("状态错误") : ValidationResult.Success; + + } + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/Device/DevicePushRecodeServices.cs b/BPA.KitChen.StoreManagement.Application/Service/Device/DevicePushRecodeServices.cs index 18f9efe..ff82f94 100644 --- a/BPA.KitChen.StoreManagement.Application/Service/Device/DevicePushRecodeServices.cs +++ b/BPA.KitChen.StoreManagement.Application/Service/Device/DevicePushRecodeServices.cs @@ -37,7 +37,18 @@ namespace BPA.KitChen.StoreManagement.Application.Service.Device.Dtos { return await _devicePushRecodeService.Add(input); } - + + /// + /// 修改 + /// + /// + /// + [HttpGet("/api/devicepushrecode/update")] + public async Task Update(string id) + { + return await _devicePushRecodeService.Update(id); + } + /// /// 删除 /// diff --git a/BPA.KitChen.StoreManagement.Application/Service/Device/Services/DevicePushRecodeService.cs b/BPA.KitChen.StoreManagement.Application/Service/Device/Services/DevicePushRecodeService.cs index a8e299a..a315864 100644 --- a/BPA.KitChen.StoreManagement.Application/Service/Device/Services/DevicePushRecodeService.cs +++ b/BPA.KitChen.StoreManagement.Application/Service/Device/Services/DevicePushRecodeService.cs @@ -72,11 +72,27 @@ namespace BPA.KitChen.StoreManagement.Application.Service.Device.Dtos data.Topic= Topic; data.DataResore = JsonConvert.SerializeObject(JsonConvert.DeserializeObject(input.Data.ToString())); var res=await Push(Topic, new PushData() { Data=input.Data, DeviceId= input.DeviceAutoKey }); - data.Status = res ? CommonStatus.ENABLE : CommonStatus.DISABLE; + data.Status = res == "success" ? CommonStatus.ENABLE : CommonStatus.DISABLE; await _db.Insertable(data).CallEntityMethod(t => t.Create()).ExecuteCommandAsync(); - - return res; + + return res == "success"; + } + + + public async Task Update(string id) + { + var data = _db.Queryable().Where(x => x.Id == id).First(); + data.Status = CommonStatus.ENABLE; + var respush = await Push(data.Topic, new PushData() { Data = data.DataResore, DeviceId = data.DeviceAutoKey }); + if (respush != "success") + { + data.Description = respush; + data.Status = CommonStatus.DISABLE; + } + var res = await _db.Updateable(data).ExecuteCommandAsync(); + return res > 0; } + /// /// 删除 /// @@ -97,7 +113,7 @@ namespace BPA.KitChen.StoreManagement.Application.Service.Device.Dtos throw Oops.Oh("删除失败"); } } - private async Task Push(string Topic,PushData data) + private async Task Push(string Topic,PushData data) { try { @@ -117,11 +133,11 @@ namespace BPA.KitChen.StoreManagement.Application.Service.Device.Dtos //string aa = bPAPackage.Serialize(false); var applictionmessage = new MqttApplicationMessageBuilder().WithTopic(Topic).WithPayload(bPAPackage.Serialize(false)).WithAtLeastOnceQoS().Build(); await _mqttClient.PublishAsync(applictionmessage); - return true; + return "success"; } catch (Exception e) { - throw Oops.Oh("下发错误,错误信息:"+e.Message); + return "下发错误,错误信息:" + e.Message; } } private string GetTopic(int type,string deviceKey) diff --git a/BPA.KitChen.StoreManagement.Application/Service/Device/Services/IDevicePushRecodeService.cs b/BPA.KitChen.StoreManagement.Application/Service/Device/Services/IDevicePushRecodeService.cs index d676e59..2e495dd 100644 --- a/BPA.KitChen.StoreManagement.Application/Service/Device/Services/IDevicePushRecodeService.cs +++ b/BPA.KitChen.StoreManagement.Application/Service/Device/Services/IDevicePushRecodeService.cs @@ -22,6 +22,8 @@ namespace BPA.KitChen.StoreManagement.Application.Service.Device.Dtos /// Task Add(DevicePushRecodeDtoInput input); + Task Update(string id); + /// /// 删除 /// diff --git a/BPA.KitChen.StoreManagement.Application/Service/Shop/Dtos/StoreInfoQueryInputDto.cs b/BPA.KitChen.StoreManagement.Application/Service/Shop/Dtos/StoreInfoQueryInputDto.cs new file mode 100644 index 0000000..8479a37 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/Shop/Dtos/StoreInfoQueryInputDto.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.Shop.Dtos +{ + public class StoreInfoQueryInputDto + { + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/Shop/Dtos/StoreQueryDto.cs b/BPA.KitChen.StoreManagement.Application/Service/Shop/Dtos/StoreQueryDto.cs new file mode 100644 index 0000000..9f5070d --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/Shop/Dtos/StoreQueryDto.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.Shop.Dtos +{ + public class StoreQueryDto + { + public string Id { get; set; } + public string Name { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/Shop/ShopService.cs b/BPA.KitChen.StoreManagement.Application/Service/Shop/ShopService.cs index 1f3e973..94f4012 100644 --- a/BPA.KitChen.StoreManagement.Application/Service/Shop/ShopService.cs +++ b/BPA.KitChen.StoreManagement.Application/Service/Shop/ShopService.cs @@ -1,8 +1,12 @@ -using BPA.KitChen.StoreManagement.Application.Service.Shop.Dtos; +using BPA.KitChen.StoreManagement.Application.BaseDto; +using BPA.KitChen.StoreManagement.Application.Service.Shop.Dtos; +using BPA.KitChen.StoreManagement.Application.Service.ShopManage.FoodMenu.Dtos; using BPA.KitChen.StoreManagement.Core.Common.Const; using BPA.KitChen.StoreManagement.Core.Entity; using BPA.KitChen.StoreManagement.SqlSugar; +using BPA.Models.BPA_Kitchen; using Furion; +using Furion.DatabaseAccessor; using Furion.DependencyInjection; using Furion.DynamicApiController; using Furion.FriendlyException; @@ -78,7 +82,7 @@ namespace BPA.KitChen.StoreManagement.Application.Service.Shop { throw Oops.Oh($"数据不存在"); } - var data2= await SqlSugarDb.Db.Queryable().FirstAsync(x => x.Id != inputDto.Id&&x.Name==inputDto.Name); + var data2= await SqlSugarDb.Db.Queryable().FirstAsync(x => x.Id != inputDto.Id&&x.Name==inputDto.Name); if (data2 != null) { throw Oops.Oh($"名称存在"); @@ -102,5 +106,57 @@ namespace BPA.KitChen.StoreManagement.Application.Service.Shop return res > 0; } + + + /// + /// 获取店铺列表 + /// + /// + /// + [HttpPost("/api/Store/GetStoreList")] + public async Task> GetStoreList(StoreInfoQueryInputDto inputDto) + { + return await SqlSugarDb.Db.Queryable().Where(x => x.IsDeleted == 0) + .OrderBy(a => a.CreateAt, OrderByType.Desc) + .Select(a => new StoreQueryDto + { + Id = a.Id, + Name = a.Name + }) + .ToListAsync(); + } + + /// + /// 获取店铺商品 + /// + /// + /// + [HttpPost("/api/Store/GetStoreGoods")] + public async Task GetStoreGoodsAsync(StoreGoodsQueryInputDto inputDto) + { + var total = new RefAsync(); + var data = await SqlSugarDb.Db + .Queryable() + .Where((s) => s.IsDeleted == 0 ) + .Where((s) => s.StoreId == inputDto.StoreId) + .WhereIF(!string.IsNullOrEmpty(inputDto.FoodMenuId), (s) => s.FoodMenuId == inputDto.FoodMenuId) + .WhereIF(!string.IsNullOrWhiteSpace(inputDto.GoodsName), (s) => s.FoodName.Contains(inputDto.GoodsName)) + .WhereIF(inputDto.IsDevice != null, (s) => s.IsDevice == inputDto.IsDevice) + .WhereIF(inputDto.Status != null, (s) => s.Status == inputDto.Status) + .WhereIF(inputDto.StopSales != null, (s) => s.StopSales == inputDto.StopSales) + .OrderBy((s) => s.IsDevice, OrderByType.Asc) + .Select((s) => new StoreGoodsBaseDto() + { + Id = s.Id.SelectAll(), + GoodsId = s.FoodId, + Goods_Name = s.FoodName + }) + .ToPageListAsync(inputDto.Current, inputDto.PageSize, total); + return new PageUtil() + { + Data = data, + Total = total + }; + } } } diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponHelperServices/CouponHelperServices.cs.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponHelperServices/CouponHelperServices.cs.cs new file mode 100644 index 0000000..0575828 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponHelperServices/CouponHelperServices.cs.cs @@ -0,0 +1,767 @@ +using Furion; +using Furion.DependencyInjection; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using BPA.Kitchen.Core.Common; +using BPA.KitChen.StoreManagement.SqlSugar; +using BPA.KitChen.StoreManagement.Application.BaseDto; +using BPA.KitChen.StoreManagement.Core.Entity; +using BPA.KitChen.StoreManagement.Core.Entity.Coupon; +using BPA.KitChen.StoreManagement.Core.Enum; +using BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.CouponServices.Dtos; +using BPA.KitChen.StoreManagement.Core.Common; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.CouponHelperServices.Dtos +{ + public class CouponHelperServices : SupperRepository, ICouponHelperServices, ITransient + { + private readonly SqlSugarScope db; // 核心对象:拥有完整的SqlSugar全部功能 + public CouponHelperServices() + { + db = SqlSugarDb.Db; + } + + + + #region 检查项 + /// + /// 检查是否领取过优惠券(判断是否新人) + /// + /// + /// + public async Task IsGetCouponCheck(string memberId) + { + var result = new ResultEntity() { IsSuccess = false }; + + var data = db.Queryable((a, b) => new JoinQueryInfos( + JoinType.Left, a.Customer_Id == b.Id)) + .Where((a, b) => b.Id == memberId) + .ToList(); + if (data.Count > 0) + { + result.IsSuccess = true; + + } + else + { + result.Msg = "当前用户领取过优惠券"; + } + return result; + } + + /// + /// 检查优惠券是否可用 + /// + /// + /// + public async Task IsUseCouponCheck(string couponId) + { + var result = new ResultEntity() { IsSuccess = false }; + + var data = await db.Queryable() + .Where(x => x.Id == couponId && x.IsDeleted == 0 && x.ValidStatus == 1 && x.ValidStatus == 1).ToListAsync(); + if (data.Count > 0) + { + result.IsSuccess = true; + + } + else + { + result.Msg = "当前优惠券不存在或不可用"; + } + return result; + } + + + /// + /// 检查优惠券用户是否可用 + /// + /// + /// + /// + public async Task IsMemberUseCouponCheck(string couponId, string memberId) + { + var result = new ResultEntity() { IsSuccess = false }; + + result = await IsUseCouponCheck(couponId); + + if (result.IsSuccess) + { + var customerCoupon = db.Queryable() + .Where(x => x.IsDeleted == 0 && x.State == 1 && x.Coupon_Id == couponId && x.Customer_Id == memberId && x.Valid_EndTime > DateTime.Now) + .ToList(); + if (customerCoupon.Count <= 0) + { + result.IsSuccess = false; + result.Msg = "当前用户的优惠券不存在或不可用"; + } + } + + return result; + } + + + + /// + ///检查用户是否瞒足优惠券领取数量限制(是否还能在领取此券) + /// + /// + /// + /// + public async Task IsSatisfyCouponGetLimitCheck(string couponId, string memberId) + { + var result = new ResultEntity() { IsSuccess = false }; + + + //1.查询优惠券 + var coupon = db.Queryable().First(x => x.Id == couponId); + if (coupon.GetLimit == 0) + { + result.IsSuccess = true; + } + else + { + //2.查询优惠券用户领取记录 + var customerCoupons = await db.Queryable().Where(x => x.Coupon_Id == couponId && x.Customer_Id == memberId).ToListAsync(); + //判断领取记录是否满足优惠券领取限制 + if (customerCoupons.Count < coupon.GetLimit) + { + result.IsSuccess = true; + } + else + { + result.Msg = "已达到优惠券最大领取数量"; + } + + } + + + return result; + } + + + #endregion + + /// s + /// (导入)验证会员优惠券领取限制 + /// + /// + /// + /// + public async Task CouponGetLimitCheck(string couponId, List memberInfoDtos) + { + var notAvailable = new List(); + var available = new List(); + + var result = await IsUseCouponCheck(couponId); + if (!result.IsSuccess) + { + foreach (var item in memberInfoDtos) + { + notAvailable.Add(new MemberInfoDto() + { + MemberId = item.MemberId, + Phone = item.Phone, + Msg = result.Msg + }); + } + } + else + { + + //1.查询生效的优惠券信息 + var couponInfo = await db.Queryable().Where(x => x.Id == couponId && x.ValidStatus == 1).FirstAsync(); + + //2.查询会员领取的优惠券 + var customerCoupon = db.Queryable() + .Where(x => x.Coupon_Id == couponId && memberInfoDtos.Select(y => y.MemberId).Contains(x.Customer_Id)) + .ToList(); + + //3.筛选出没有领取过优惠券的会员 + available = memberInfoDtos.Where(x => !customerCoupon.Select(y => y.Customer_Id).Contains(x.MemberId)).ToList(); + + //4.赛选满足条件的会员 + foreach (var item in customerCoupon.GroupBy(x => x.Customer_Id)) + { + + var phone = memberInfoDtos.FirstOrDefault(x => x.MemberId == item.First().Customer_Id).Phone; + //领取数量限制 + if (item.Count() <= couponInfo.GetLimit) + { + //优惠券是否过期 + if (couponInfo.TimeType == 1 && couponInfo.ValidEndTime < DateTime.Now) + { + notAvailable.Add(new MemberInfoDto() + { + MemberId = item.First().Customer_Id, + Phone = phone, + Msg = "优惠券已过期" + }); + } + else + { + available.Add(new MemberInfoDto() + { + MemberId = item.First().Customer_Id, + Phone = phone, + }); + } + } + else + { + notAvailable.Add(new MemberInfoDto() + { + MemberId = item.First().Customer_Id, + Phone = phone, + Msg = "会员超出领卷数量限制" + }); ; + } + } + } + + + return new MemberInfoOutDto() + { + Available = available, + NotAvailable = notAvailable + }; + } + /// + /// 获取所有可用优惠券(附加剩余数量和使用限制) + /// + /// + public async Task> GetCouponCanUseCountAndLimit(string couponId = null) + { + var result = new List(); + // 查询出可以可以使用的优惠券 + var couponList = await db.Queryable().Where(x => x.IsDeleted == 0 && x.ValidStatus == 1) + .WhereIF(!string.IsNullOrWhiteSpace(couponId), x => x.Id == couponId) + .ToListAsync(); + + var couponListData = new List(); + //去掉过期优惠券 + foreach (var item in couponList) + { + if (item.TimeType == 1 && item.ValidEndTime <= DateTime.Now) + { + couponListData.Add(item); + } + } + couponList = couponList.Where(x => !couponListData.Contains(x)).ToList(); + var couponIds = couponList.Select(x => x.Id).ToList(); + + ////查询出优惠券下的所有批次 + var batchNoList = await db.Queryable().Where(x => couponIds.Contains(x.Coupon_Id)).ToListAsync(); + + //查询所有领取过得优惠券 + var GetCouponList = await db.Queryable().Where(x => couponIds.Contains(x.Coupon_Id)).ToListAsync(); + + foreach (var item in couponList) + { + var list = new List(); + //所有发送批次 + var couponRange = batchNoList.Where(x => x.Coupon_Id == item.Id).ToList(); + + foreach (var entity in couponRange) + { + //此批的领取情况 + var GetCount = GetCouponList.Where(x => x.Coupon_Id == item.Id && x.Coupon_Range_Id == entity.Id).ToList(); + + list.Add(new BatchInfo() + { + Id = entity.Id, + BatchNo = entity.BatchNo, + SendNum = entity.SendNum, + GetNum = GetCount.Count + }); + } + result.Add(new CouponCanUseCountAndLimitOutDto() + { + CouponId = item.Id, + CouponName = item.CouponTitle, + Limit = item.GetLimit == 0 ? list.Sum(x => x.SendNum) : item.GetLimit, + CanUseCount = list.Sum(x => x.SendNum) - list.Sum(x => x.GetNum), + BatchInfo = list + }); + } + return result; + + } + + + /// + /// 发送优惠券(同时记录发送记录) + /// + /// 优惠券 + /// 批次信息 + /// 会员 + /// 类型 + /// + public async Task SendCoupon(string couponId, string couponRangeId, int sendCount, string memberId, E_CouponGitType type, SqlSugarScope sqlSugarClient = null) + { + if (sqlSugarClient == null) + { + sqlSugarClient = db; + } + var result = new ResultEntity() { IsSuccess = false }; + var coupon = new BPA_Coupon(); + //查询会员 + var member = sqlSugarClient.Queryable().Where(x => x.IsDeleted == 0 && x.Status == 0 && x.Id == memberId).ToList().FirstOrDefault(); + if (member != null) + { + //2.检查优惠券 + result = await IsUseCouponCheck(couponId); + if (result.IsSuccess) + { + //查询优惠券 + coupon = db.Queryable().First(x => x.Id == couponId); + + //3.检查用户是是否满足优惠券领取数量限制 + result = await IsSatisfyCouponGetLimitCheck(couponId, memberId); + if (result.IsSuccess) + { + var list = new List(); + //发券 + for (int i = 0; i < sendCount; i++) + { + var temp = new BPA_CustomerCoupon + { + Customer_Id = memberId, + Coupon_Id = couponId, + Receive_Type = (int)type, + Coupon_Range_Id = couponRangeId, + State = 1, + CustomerPhone = member.Phone, + Valid_StartTime = coupon.TimeType == 1 ? coupon.ValidStartTime : DateTime.Now, + Valid_EndTime = coupon.TimeType == 1 ? coupon.ValidEndTime : DateTime.Now.AddDays(coupon.ValidFixedTerm), + IsDeleted = 0, + }; + list.Add(temp); + } + result.IsSuccess = db.Insertable(list).CallEntityMethod(t => t.Create()).ExecuteCommand() > 0; ; + if (!result.IsSuccess) + { + result.Msg = "修改失败"; + } + } + } + } + else + { + result.Msg = "会员被停用或不存在此会员"; + } + return result; + } + + + + + + + + #region 对外 + + /// + /// 获取优惠券使用范围 + /// + /// + public async Task GetCouponUseScope(string customerCouponId) + { + var result = new ResultEntity() { IsSuccess = true }; + var couponUseScope = new CouponUseScopeOutDto() { }; + var customerCoupon = await db.Queryable().Where(x => x.Id == customerCouponId).FirstAsync(); + if (customerCoupon == null) + { + result.IsSuccess = false; + result.Msg = "用户没有此优惠券"; + } + else if (customerCoupon.State != 1) + { + couponUseScope.CouponId = customerCoupon.Coupon_Id; + result.IsSuccess = false; + result.Msg = $"优惠券不可以用:{(customerCoupon.State == 2 ? "已核销" : (customerCoupon.State == 3 ? "被占用" : "失效"))}"; + } + else + { + couponUseScope.CouponId = customerCoupon.Coupon_Id; + var coupon = await db.Queryable().Where(x => x.Id == customerCoupon.Coupon_Id && x.IsDeleted == 0).FirstAsync(); + if (coupon == null) + { + result.IsSuccess = false; + result.Msg = "优惠券不存在"; + } + else if (coupon.ValidStatus != 1) + { + result.IsSuccess = false; + result.Msg = "优惠券被作废或者停用"; + } + + else + { + + //批次信息 + var couponRange = await db.Queryable().Where(x => x.Id == customerCoupon.Coupon_Range_Id && x.IsDeleted == 0).FirstAsync(); + + if (couponRange == null) + { + result.IsSuccess = false; + result.Msg = "当前批次信息不可用"; + } + + //适用店铺 + var storeList = new List(); + + var couponRangeRelations = await db.Queryable().Where(x => x.Coupon_Range_Id == couponRange.Id && x.IsDeleted == 0 && x.Status == CommonStatus.ENABLE).ToListAsync(); + if (couponRangeRelations.Count > 0) + { + var ids = couponRangeRelations.Select(x => x.RangeTypeId).ToList(); + if (couponRange.RangeType == 1) + { + foreach (var item in couponRangeRelations) + { + storeList.Add(new UseScopeListOutDto() + { + Id = item.RangeTypeId + }); + } + } + } + //适用商品 + var goodsList = new List(); + var couponGoodsRelations = await db.Queryable().Where(x => x.Coupon_Range_Id == couponRange.Id && x.IsDeleted == 0 && x.Status == CommonStatus.ENABLE).ToListAsync(); + if (couponGoodsRelations.Count > 0) + { + foreach (var item in couponGoodsRelations) + { + goodsList.Add(new UseScopeListOutDto() + { + + Id = item.GoodsId + }); + } + } + + couponUseScope.StoreList = storeList; + couponUseScope.GoodsList = goodsList; + + result.Data = couponUseScope; + } + } + + return result; + + } + + /// + /// 查看领取的优惠券 + /// + /// + /// + public async Task WacthCoupon(CustomerCouponPageDto input) + { + var total = new RefAsync(); + var data = await db.Queryable((t, x) => t.Coupon_Id == x.Id) + .Where(t => t.IsDeleted == 0) + .Where(t => t.State == input.State) + //.Where((t, x) => x.ValidStatus == input.State) + .Where(t => t.Valid_EndTime >= DateTime.Now) + .Where(t => t.CustomerPhone == input.CustomerPhone || t.Customer_Id == input.CustomerId) + .Select((t, x) => new CustomerCouponOutputDto + { + CustomerId = t.Customer_Id, + CouponTitle = x.CouponTitle, + CouponId = t.Coupon_Id, + Id = t.Id, + State = t.State, + CouponRangeId = t.Coupon_Range_Id, + OrderId = t.Order_Id, + ReceiveType = t.Receive_Type, + ValidStartTime = t.Valid_StartTime, + ValidEndTime = t.Valid_EndTime, + CouponValue = x.CouponValue, + Condition = x.Condition + }).ToPageListAsync(input.Current, input.PageSize, total); + return new PageUtil + { + Data = data, + Total = total + }; + } + + /// + /// 获取能使用的优惠券 + /// + /// + public async Task GetCanUseCouponByWeChat(WeChatCanUseCouponQueryInputDto inputDto) + { + + var result = new ResultEntity() { IsSuccess = true }; + //1.查询会员 + var member = db.Queryable().Where(x => x.PlatformMemberId == inputDto.OpenId).ToList().FirstOrDefault(); + + if (member == null) + { + result.Msg = "会员不存在"; + return result; + } + var StoreGoodss = db.Queryable().Where(x => inputDto.StoreGoodsIds.Contains(x.Id)).ToList(); + + //店铺 + var storeIds = StoreGoodss.Select(x => x.Id).ToList(); + + + //商品 + var GoodsIds = db.Queryable((a, b) => + new JoinQueryInfos(JoinType.Left, a.Id == b.FoodMenuId)) + .Where((a, b) => storeIds.Contains(b.StoreId)) + .Select((a, b) => a.GoodsId).ToList(); + + + + + //2.查询当前会员的所有库用优惠券 + var customerCoupon = db.Queryable() + .Where(x => x.Customer_Id == member.MemberInfo_Id && x.IsDeleted == 0 && x.State == 1 && x.Valid_EndTime > DateTime.Now) + .ToList(); + var couponRangeId = customerCoupon.Select(x => x.Coupon_Range_Id).ToList(); + + //店铺判定 + var batchScopeLimit = db.Queryable((a, b) => new JoinQueryInfos(JoinType.Left, a.Coupon_Range_Id == b.Id)) + .Where((a, b) => couponRangeId.Contains(a.Coupon_Range_Id)) + .Select((a, b) => new BatchScopeLimitDto() + { + Coupon_Id = b.Coupon_Id, + Coupon_Range_Id = a.Coupon_Range_Id, + RangeType = b.RangeType, + StoreId = b.RangeType == 1 ? a.RangeTypeId : "", + }) + .ToList(); + + var rangeId = new List(); + foreach (var item in batchScopeLimit) + { + var coupon_Range_Id = ""; + if (item.RangeType == 1 && storeIds.Contains(item.StoreId)) + { + coupon_Range_Id = item.Coupon_Range_Id; + } + + //商品判定 + var goodsrange = db.Queryable() + .Where(x => x.Coupon_Range_Id == item.Coupon_Range_Id) + .ToList(); + + if (goodsrange.Count > 0) + { + if (goodsrange.Where(x => GoodsIds.Contains(x.GoodsId)).Select(x => x.Coupon_Range_Id).ToList().Count <= 0) + { + coupon_Range_Id = ""; + } + } + if (!string.IsNullOrWhiteSpace(coupon_Range_Id)) + { + rangeId.Add(coupon_Range_Id); + } + + } + + + var date = db.Queryable((a, b) => new JoinQueryInfos(JoinType.Left, a.Coupon_Id == b.Id)) + .Where((a, b) => rangeId.Contains(a.Coupon_Range_Id) && b.Condition <= inputDto.totalPrice) + .Where((a, b) => a.IsDeleted == 0 && a.State == 1 && a.Valid_EndTime > DateTime.Now && b.IsDeleted == 0 && b.ValidStatus == 1) + .Where((a, b) => a.Customer_Id == member.MemberInfo_Id) + .Select((a, b) => new CustomerCouponOutputDto + { + Id = a.Id.SelectAll(), + Condition = b.Condition, + CouponTitle = b.CouponTitle, + CouponValue = b.CouponValue, + Remark = b.Remarks, + }).ToList(); + result.Data = date; + if (date.Count <= 0) + { + result.IsSuccess = false; + } + return result; + } + + + + /// + /// 扫码领券 + /// + /// + /// + public async Task ScanCodeGetCoupon(ScanCodeGetCouponInputDto inputDto) + { + var result = new ResultEntity() { IsSuccess = false }; + + + var member = await db.Queryable().FirstAsync(x => x.Id == inputDto.MemberId); + + if (member == null) + { + result.IsSuccess = false; + result.Msg = "会员不存在"; + return result; + } + //查询优惠券可用批次 + + var couponRanges = db.Queryable().Where(x => x.IsDeleted == 0 && x.Coupon_Id == inputDto.CouponId).ToList(); + + if (couponRanges.Count > 0) + { + var groupId = couponRanges.First().GroupId; + if (groupId != member.GroupId) + { + result.IsSuccess = false; + result.Msg = "供应商错误"; + return result; + } + } + + //查询优惠券的使用情况 + var customerCoupons = db.Queryable() + .Where(x => couponRanges.Select(y => y.Coupon_Id).Contains(x.Coupon_Id)) + .GroupBy(x => x.Coupon_Id) + .Select(x => new { Count = SqlFunc.AggregateCount(x.Coupon_Id), Coupon_Id = x.Coupon_Id }).ToList(); + + var data = (from a in couponRanges + join b in customerCoupons on a.Coupon_Id equals b.Coupon_Id into ab + from abinfo in ab.DefaultIfEmpty() + where a.SendNum > (abinfo?.Count ?? 0) + select a).ToList(); + if (data.Count <= 0) + { + result.IsSuccess = false; + result.Msg = "没有可用批次"; + return result; + } + result.IsSuccess = await App.GetService().ReceiveCouponByInput(new CustomerCouponInputDto() + { + CouponId = inputDto.CouponId, + MemberId = new List() { inputDto.MemberId }, + CouponRangeId = data.First().Id, + CouponGitType = E_CouponGitType.线下门店扫码 + }); + return result; + } + + + + #endregion + + #region 优惠券核销 + + /// + /// 优惠券核销 + /// + /// + /// + public async Task CouponWriteoff(CouponWriteoffInputDto inputDto) + { + var result = new ResultEntity() { IsSuccess = false }; + if (string.IsNullOrWhiteSpace(CurrentUser.TenantId)) + { + result.Msg = "加盟商不能为空"; + return result; + } + try + { + db.Ado.BeginTran(); + if (inputDto.Type == 1)//第三方优惠券 + { + + + foreach (var item in inputDto.CouponId) + { + var paperCoupon = await db.Queryable().FirstAsync(x => x.Id == item); + + if (paperCoupon == null) + { + result.Msg = "优惠券不存在"; + return result; + } + + var res = await db.Insertable(new BPA_PaperCouponWriteoffLog() + { + CreateAt = DateTime.Now, + GroupId = CurrentUser.TenantId, + OrderId = inputDto.OrderId, + PaperCouponId = item, + + }).ExecuteCommandAsync(); + result.IsSuccess = res > 0; + if (!result.IsSuccess) + { + throw new Exception("优惠券核销错误"); + } + } + } + else + { + foreach (var item in inputDto.CouponId) + { + var goodsoupon = await db.Queryable().FirstAsync(x => x.Id == item); + + if (goodsoupon == null) + { + result.Msg = "优惠券不存在"; + return result; + } + + var res = await db.Insertable(new BPA_GoodsCouponWriteoffLog() + { + CreateAt = DateTime.Now, + GroupId = CurrentUser.TenantId, + OrderId = inputDto.OrderId, + GoodsCouponId = item, + + }).ExecuteCommandAsync(); + result.IsSuccess = res > 0; + if (!result.IsSuccess) + { + throw new Exception("抵扣券核销错误"); + } + } + } + db.Ado.CommitTran(); + } + catch (Exception ex) + { + db.Ado.RollbackTran(); + result.Msg=ex.ToString(); + } + return result; + } + + /// + ///获取 优惠群核销记录 + /// + /// + /// + public async Task GetPOSCouponWriteoffRecord(string orderId) + { + var result = new ResultEntity() { IsSuccess = true }; + var data = new POSCouponWriteoffRecordOutDto(); + data.GoodsCouponWriteoffLogs = await db.Queryable().Where(x => x.OrderId == orderId).ToListAsync(); + data.PaperCouponWriteoffLogs = await db.Queryable().Where(x => x.OrderId == orderId).ToListAsync(); + result.Data = data; + return result; + } + + public Task SendCoupon(string couponId, string couponRangeId, int sendCount, string memberId, E_CouponGitType type, SqlSugarClient sqlSugarClient = null) + { + throw new NotImplementedException(); + } + + #endregion + + + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponHelperServices/Dtos/BatchScopeLimitDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponHelperServices/Dtos/BatchScopeLimitDto.cs new file mode 100644 index 0000000..9dea94f --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponHelperServices/Dtos/BatchScopeLimitDto.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.CouponHelperServices.Dtos +{ + public class BatchScopeLimitDto + { + public string Coupon_Id { get; set; } + + public string Coupon_Range_Id { get; set; } + + public int RangeType { get; set; } + + public string StoreId { get; set; } + + public string StoreTypeId { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponHelperServices/Dtos/Class1.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponHelperServices/Dtos/Class1.cs new file mode 100644 index 0000000..2913a99 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponHelperServices/Dtos/Class1.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.CouponHelperServices.Dtos +{ + internal class Class1 + { + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponHelperServices/Dtos/CouponCanUseCountAndLimitOutDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponHelperServices/Dtos/CouponCanUseCountAndLimitOutDto.cs new file mode 100644 index 0000000..5e5ce20 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponHelperServices/Dtos/CouponCanUseCountAndLimitOutDto.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.CouponHelperServices.Dtos +{ + public class CouponCanUseCountAndLimitOutDto + { + /// + /// 优惠券id + /// + public string CouponId { get; set; } + + public string CouponName { get; set; } + + /// + /// 能使数量 + /// + public int CanUseCount { get; set; } + + /// + /// 领取限制 0无限制 + /// + public int Limit { get; set; } + + public List BatchInfo { get; set; } + } + + public class BatchInfo + { + + public string Id { get; set; } + + + /// + /// 批次号 + /// + public string BatchNo { get; set; } + + + /// + /// 发送数量 + /// + public int SendNum { get; set; } + + /// + /// 领取数量 + /// + public int GetNum { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponHelperServices/Dtos/CouponUseScopeOutDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponHelperServices/Dtos/CouponUseScopeOutDto.cs new file mode 100644 index 0000000..35fae28 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponHelperServices/Dtos/CouponUseScopeOutDto.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.CouponHelperServices.Dtos +{ + public class CouponUseScopeOutDto + { + + public string CouponId { get; set; } + public List StoreList { get; set; } + + public List GoodsList { get; set; } + } + + public class UseScopeListOutDto + { + public string Id { get; set; } + + public string Name { get; set; } + + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponHelperServices/Dtos/CouponWriteoffInputDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponHelperServices/Dtos/CouponWriteoffInputDto.cs new file mode 100644 index 0000000..987c2c3 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponHelperServices/Dtos/CouponWriteoffInputDto.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.CouponHelperServices.Dtos +{ + public class CouponWriteoffInputDto + { + /// + /// 订单ID + /// + public string OrderId { get; set; } + + /// + /// 优惠券ID + /// + public List CouponId { get; set; } + + // 1 第三方抵扣券 2 商品抵扣券 + public int Type { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponHelperServices/Dtos/GetCouponInputDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponHelperServices/Dtos/GetCouponInputDto.cs new file mode 100644 index 0000000..dac9252 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponHelperServices/Dtos/GetCouponInputDto.cs @@ -0,0 +1,14 @@ +using BPA.KitChen.StoreManagement.Application.BaseDto; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.CouponHelperServices.Dtos +{ + public class GetCouponInputDto : PageInputBase + { + + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponHelperServices/Dtos/MemberInfoDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponHelperServices/Dtos/MemberInfoDto.cs new file mode 100644 index 0000000..3b9092a --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponHelperServices/Dtos/MemberInfoDto.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.CouponHelperServices.Dtos +{ + public class MemberInfoDto + { + [DisplayName("手机号")] + public string Phone { get; set; } + public string MemberId { get; set; } + + public string Msg { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponHelperServices/Dtos/MemberInfoOutDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponHelperServices/Dtos/MemberInfoOutDto.cs new file mode 100644 index 0000000..cabd912 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponHelperServices/Dtos/MemberInfoOutDto.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.CouponHelperServices.Dtos +{ + + public class MemberInfoOutDto + { + + /// + /// 不可用 + /// + public List NotAvailable { get; set; } + + //可用 + public List Available { get; set; } + + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponHelperServices/Dtos/POSCouponWriteoffRecordOutDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponHelperServices/Dtos/POSCouponWriteoffRecordOutDto.cs new file mode 100644 index 0000000..6274e00 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponHelperServices/Dtos/POSCouponWriteoffRecordOutDto.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using BPA.KitChen.StoreManagement.Core.Entity.Coupon; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.CouponHelperServices.Dtos +{ + public class POSCouponWriteoffRecordOutDto + { + public List PaperCouponWriteoffLogs { get; set; } + public List GoodsCouponWriteoffLogs { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponHelperServices/Dtos/ScanCodeGetCouponInputDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponHelperServices/Dtos/ScanCodeGetCouponInputDto.cs new file mode 100644 index 0000000..3c185ef --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponHelperServices/Dtos/ScanCodeGetCouponInputDto.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.CouponHelperServices.Dtos +{ + public class ScanCodeGetCouponInputDto + { + public string CouponId { get; set; } + public string MemberId { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponHelperServices/Dtos/WeChatCanUseCouponQueryInputDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponHelperServices/Dtos/WeChatCanUseCouponQueryInputDto.cs new file mode 100644 index 0000000..78c03fb --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponHelperServices/Dtos/WeChatCanUseCouponQueryInputDto.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.CouponHelperServices.Dtos +{ + public class WeChatCanUseCouponQueryInputDto + { + public List StoreGoodsIds { get; set; } + public string OpenId { get; set; } + public decimal totalPrice { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponHelperServices/ICouponHelperServices.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponHelperServices/ICouponHelperServices.cs new file mode 100644 index 0000000..bb4d329 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponHelperServices/ICouponHelperServices.cs @@ -0,0 +1,118 @@ +using BPA.KitChen.StoreManagement.Application.BaseDto; +using BPA.KitChen.StoreManagement.Core.Enum; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.CouponHelperServices.Dtos +{ + public interface ICouponHelperServices + { + + #region 检查项 + + /// + /// 检查是否领取过优惠券 + /// + /// + /// + Task IsGetCouponCheck(string memberId); + + /// + /// 检查优惠券是否可用 + /// + /// + /// + Task IsUseCouponCheck(string couponId); + + /// + /// 检查优惠券用户是否可用 + /// + /// + /// + /// + Task IsMemberUseCouponCheck(string couponId, string memberId); + + /// + ///检查用户是否瞒足优惠券领取数量限制(是否还能在领取此券) + /// + /// + /// + /// + Task IsSatisfyCouponGetLimitCheck(string couponId, string memberId); + + + #endregion + + + /// + ///(导入)验证会员优惠券领取限制 + /// + /// + /// + /// + Task CouponGetLimitCheck(string CouponId, List memberInfoDtos); + + + /// + /// 获取所有可用优惠券(附加剩余数量和使用限制) + /// + /// + Task> GetCouponCanUseCountAndLimit(string couponId = null); + + + /// + /// 发送优惠券(同时记录发送记录) + /// + /// 优惠券 + /// 批次信息 + /// 会员 + /// 类型 + /// + Task SendCoupon(string couponId, string couponRangeId, int sendCount, string memberId, E_CouponGitType type, SqlSugarScope sqlSugarClient = null); + + + #region 对外 + /// + /// 获取优惠券使用范围 + /// + /// + Task GetCouponUseScope(string customerCouponId); + + /// + /// 获取能使用的优惠券 + /// + /// + Task GetCanUseCouponByWeChat(WeChatCanUseCouponQueryInputDto inputDto); + + /// + /// 扫码领券 + /// + /// + /// + Task ScanCodeGetCoupon(ScanCodeGetCouponInputDto inputDto); + + #endregion + + #region 优惠券核销 + + /// + /// 优惠券核销 + /// + /// + /// + Task CouponWriteoff(CouponWriteoffInputDto inputDto); + + /// + ///获取 优惠群核销记录 + /// + /// + /// + Task GetPOSCouponWriteoffRecord(string orderId); + + #endregion + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponService.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponService.cs new file mode 100644 index 0000000..3e7e85a --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponService.cs @@ -0,0 +1,337 @@ + +using BPA.KitChen.StoreManagement.Application.BaseDto; +using BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.CouponServices.Dtos; +using BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.CouponServices.Dtos.member; +using Furion.DependencyInjection; +using Furion.DynamicApiController; +using Furion.RemoteRequest; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Components.Forms; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon +{ + /// + /// 优惠卷 + /// + [ApiDescriptionSettings("优惠券", Tag = "优惠卷管理", SplitCamelCase = false)] + public class CouponService : IDynamicApiController, ITransient + { + readonly ICouponServices _couponServices; + /// + /// + /// + /// + public CouponService(ICouponServices couponServices) + { + _couponServices = couponServices; + + } + + /// + /// 获取商品类型 + /// + /// + [Get("/api/coupon/goodstype")] + public async Task> GetGoodsType() + { + return await _couponServices.GetGoodsType(); + } + + + /// + /// 获取商品 + /// + /// + /// + [Get("/api/coupon/goods")] + public async Task> GetGoods(string GoodsTypeId) + { + return await _couponServices.GetGoods(GoodsTypeId); + } + + /// + /// 获取会员信息 + /// + /// + /// + [HttpPost("/api/coupon/GetCustomerInfo")] + public async Task> GetCustomerInfo(CustomerInfoInputDto input) + { + return await _couponServices.GetCustomerInfo(input); + } + + + /// + /// 获取优惠卷_分页 + /// + /// + /// + [HttpPost, ApiDescriptionSettings(SplitCamelCase = false)] + public async Task CouponPgage([FromBody] PageCouponInputDto inputDto) + { + return await _couponServices.GetCouponPgageAsync(inputDto); + } + + /// + /// 获取优惠卷状态和类型 1.优惠卷状态 2.优惠卷类型 + /// + /// + /// + [HttpPost("/api/coupon/getCouponStatusOrType")] + public async Task> GetCouponStatusOrTypeAsync(int type) + { + return await _couponServices.GetCouponStatusOrTypeAsync(type); + + } + + /// + /// 新增优惠卷 + /// + /// + /// + [HttpPost("/api/coupon/addCoupon")] + public async Task AddCoupon(CouponBasetDto inputDto) + { + return await _couponServices.AddCoupon(inputDto); + } + + /// + /// 删除优惠卷 + /// + /// + /// + [HttpPost("/api/coupon/deleteCoupon")] + public async Task DeleteCoupon(List Ids) + { + return await _couponServices.DeleteCoupon(Ids); + } + + /// + /// 修改优惠券状态 + /// + /// + /// + public async Task UpdateCouponStatus(CouponBasetDto inputDto) + { + return await _couponServices.UpdateCouponStatus(inputDto); + } + + /// + /// 修改优惠卷 + /// + /// + /// + [HttpPost("/api/coupon/updateCoupon")] + public async Task UpdateCoupon(CouponBasetDto inputDto) + { + return await _couponServices.UpdateCoupon(inputDto); + } + + /// + /// 作废优惠卷 + /// + /// + /// + [HttpPost("/api/coupon/abolishcoupon")] + public async Task AbolishCoupon(string Id) + { + return await _couponServices.AbolishCoupon(Id); + } + + #region 优惠券领取 + /// + /// 指定客户领取 + /// + /// + /// + [HttpPut, ApiDescriptionSettings(SplitCamelCase = false)] + public async Task ReceiveCouponByInput(CustomerCouponInputDto input) + { + return await _couponServices.ReceiveCouponByInput(input); + } + /// + /// 领券分页查看SAAS用 + /// + /// + /// + [HttpPost, ApiDescriptionSettings(SplitCamelCase = false)] + public async Task GetCustomerPage(CustomerCouponPageExDto input) + { + return await _couponServices.GetCustomerPage(input); + } + /// + /// 失效顾客优惠券 + /// + /// + [HttpDelete, ApiDescriptionSettings(SplitCamelCase = false)] + public async Task AbolishCustomerCoupon(string Id) + { + return await _couponServices.AbolishCustomerCoupon(Id); + } + #endregion + + #region 对小程序暴露接口 + /// + /// 领券(支持批量领取) + /// + /// + /// + [HttpPut, ApiDescriptionSettings(SplitCamelCase = false), AllowAnonymous, NonUnify] + public async Task ReceiveCoupon([FromBody] List input) + { + return await _couponServices.ReceiveCoupon(input); + } + /// + /// 退单退券 + /// + /// + /// + [HttpPost, ApiDescriptionSettings(SplitCamelCase = false), AllowAnonymous, NonUnify] + public async Task RebackCoupon([FromBody] RebackDto input) + { + return await _couponServices.RebackCoupon(input.Id); + } + /// + /// 优惠券的使用 + /// + /// false券无效或者失效或有错误 + [HttpPost, ApiDescriptionSettings(SplitCamelCase = false), AllowAnonymous, NonUnify] + public async Task CustomerCouponOff([FromBody] CustomerCouponBaseDto input) + { + return await _couponServices.CustomerCouponOff(input); + } + /// + /// 查看领取的优惠券 + /// + /// + /// + [HttpPost, ApiDescriptionSettings(SplitCamelCase = false), AllowAnonymous, NonUnify] + public async Task WacthCoupon([FromBody] CustomerCouponPageDto input) + { + return await _couponServices.WacthCoupon(input); + } + /// + /// 回调写入优惠券状态f + /// + /// + /// + [HttpPost, ApiDescriptionSettings(SplitCamelCase = false), AllowAnonymous, NonUnify] + public async Task UpdateState(UpdateStateDto input) + { + return await _couponServices.UpdateState(input.OdrerId, input.State); + } + /// + /// 客户查询领券的详情 + /// + /// + /// + [HttpGet, ApiDescriptionSettings(SplitCamelCase = false), AllowAnonymous, NonUnify] + public async Task CustomerCouponDetail(string Id) + { + return await _couponServices.CustomerCouponDetail(Id); + } + /// + /// 查询流水日志 + /// + /// + [HttpGet, ApiDescriptionSettings(SplitCamelCase = false), AllowAnonymous, NonUnify] + public async Task> GetCouponLog(string CouponCustomerId) + { + return await _couponServices.GetCouponLog(CouponCustomerId); + } + /// + /// 查询可用券 + /// + /// + /// + [HttpPost, ApiDescriptionSettings(SplitCamelCase = false), AllowAnonymous, NonUnify] + public async Task> SelectCanUseCoupon(CustomerCouponCanUseDto input) + { + return await _couponServices.SelectCanUseCoupon(input); + } + + /// + /// 根据订单号获取用户的优惠券使用状态 + /// + /// + /// + [HttpPost, ApiDescriptionSettings(SplitCamelCase = false), AllowAnonymous, NonUnify] + public async Task> GetCouponStutasByOrderId(List OrderId) + => await _couponServices.GetCouponStutasByOrderId(OrderId); + + #endregion + + #region 优惠券记录 + /// + /// 获取发券的管理记录 + /// + /// + /// + [HttpPost, ApiDescriptionSettings(SplitCamelCase = false)] + public async Task GetCouponRecordById([FromBody] CouponRecordPageDto input) + { + return await _couponServices.GetCouponRecordById(input); + } + /// + /// 记录汇总 + /// + /// + /// + [HttpPost, AllowAnonymous, ApiDescriptionSettings(SplitCamelCase = false)] + public async Task GetCouponRecordPage(CouponRecordPageDto input) + { + return await _couponServices.GetCouponRecordPage(input); + } + /// + /// 新增发券记录 + /// + /// + /// + [HttpPut, ApiDescriptionSettings(SplitCamelCase = false)] + public async Task AddCouponSendRecord([FromBody] CouponRecordDto input) + { + return await _couponServices.AddCouponSendRecord(input); + } + /// + /// 召回优惠券 + /// + /// + /// + [HttpPost, ApiDescriptionSettings(SplitCamelCase = false)] + public async Task RecallCoupon(CouponRecordDto input) + { + return await _couponServices.RecallCoupon(input); + } + /// + /// 召回禁用优惠卷商品 + /// + /// + /// + [HttpPost, ApiDescriptionSettings(SplitCamelCase = false)] + public async Task RecallCouponGoods(CouponRecordDto input) + { + return await _couponServices.RecallCouponGoods(input); + } + /// + /// 获取发券的管理记录商品 + /// + /// + /// + [HttpPost, ApiDescriptionSettings(SplitCamelCase = false)] + public async Task GetCouponRecordGoods(CouponRecordPageDto input) + { + return await _couponServices.GetCouponRecordGoods(input); + } + #endregion + + + + + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/CouponServices.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/CouponServices.cs new file mode 100644 index 0000000..78ff4ca --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/CouponServices.cs @@ -0,0 +1,1182 @@ + +using BPA.KitChen.StoreManagement.Application.BaseDto; +using BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.CouponHelperServices.Dtos; +using BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.CouponServices.Dtos.member; +using BPA.KitChen.StoreManagement.Application.Service.ShopManage.FoodMenu; +using BPA.KitChen.StoreManagement.Application.Service.ShopManage.FoodMenu.Dtos; +using BPA.KitChen.StoreManagement.Core.Common; +using BPA.KitChen.StoreManagement.Core.Common.Const; +using BPA.KitChen.StoreManagement.Core.Entity; +using BPA.KitChen.StoreManagement.Core.Entity.Coupon; +using BPA.KitChen.StoreManagement.Core.Enum; +using BPA.KitChen.StoreManagement.SqlSugar; +using Furion; +using Furion.DependencyInjection; +using Furion.FriendlyException; +using Mapster; +using Microsoft.AspNetCore.Components.Forms; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.CouponServices.Dtos +{ + /// + /// 优惠卷 + /// + public class CouponServices : SupperRepository, ICouponServices, ITransient + { + + private readonly SqlSugarScope db; + private readonly ICouponHelperServices _couponHelperServices; + private readonly IHttpContextAccessor _httpContextAccessor; + //private readonly IActivityParticipationRecordServices _activityParticipationRecordServices; + public CouponServices(ICouponHelperServices couponHelperServices, + IHttpContextAccessor httpContextAccessor + //IActivityParticipationRecordServices activityParticipationRecordServices + ) + { + db = SqlSugarDb.Db; + _couponHelperServices = couponHelperServices; + _httpContextAccessor = httpContextAccessor; + //_activityParticipationRecordServices = activityParticipationRecordServices; + } + + /// + /// 获取优惠卷状态和类型 1.优惠卷状态 2.优惠卷类型 + /// + /// + /// + public async Task> GetCouponStatusOrTypeAsync(int type) + { + var result = new List(); + + if (type == 1) + { + foreach (var item in Enum.GetValues(typeof(E_CouponStatus))) + { + result.Add(new StatusOrTypeOutDto() + { + Key = (int)item, + Value = Enum.GetName(typeof(E_CouponStatus), item) + }); + } + } + else + { + foreach (var item in Enum.GetValues(typeof(E_CouponType))) + { + result.Add(new StatusOrTypeOutDto() + { + Key = (int)item, + Value = Enum.GetName(typeof(E_CouponType), item) + + }); + } + } + + return await Task.FromResult(result); + } + + #region 优惠卷基本操作 + + /// + /// / 获取优惠卷_分页 + /// + /// + /// + public async Task GetCouponPgageAsync(PageCouponInputDto inputDto) + { + + var result = new List(); + var total = new RefAsync(); + + var queryable = db.Queryable(); + + #region 条件查询 + queryable = queryable.Where(x => x.IsDeleted == 0) + .Where(x => x.CreateType == Convert.ToInt32(App.User.FindFirst(ClaimConst.LoginType).Value)) + .WhereIF(!string.IsNullOrWhiteSpace(inputDto.CouponTitle), + x => x.CouponTitle.Contains(inputDto.CouponTitle)) + .WhereIF(inputDto.CouponType > 0, x => x.CouponType == inputDto.CouponType) + .WhereIF(inputDto.CouponValue > 0, x => x.CouponValue == inputDto.CouponValue) + .WhereIF(inputDto.Condition > 0, x => x.Condition == inputDto.Condition) + .WhereIF(inputDto.GetLimit > 0, x => x.GetLimit == inputDto.GetLimit) + .WhereIF(inputDto.TimeType > 0, x => x.TimeType == inputDto.TimeType) + .WhereIF((inputDto.TimeType == 2 && inputDto.ValidFixedTerm > 0), + x => x.ValidFixedTerm == inputDto.ValidFixedTerm) + .WhereIF(inputDto.TimeType == 1 && inputDto.ValidStartTime.HasValue && inputDto.ValidEndTime.HasValue, + x => x.ValidStartTime >= inputDto.ValidStartTime.Value && x.ValidEndTime <= inputDto.ValidEndTime.Value.AddDays(1).AddSeconds(-1)) + .WhereIF(inputDto.ValidStatus > 0, x => x.ValidStatus == inputDto.ValidStatus) + .WhereIF(inputDto.CreateAt.HasValue, x => x.CreateAt.Date == inputDto.CreateAt.Value.Date); + + #endregion + + var obj=new List(); + //优惠券基础信息 + var data = await queryable.OrderBy(x => x.ValidStatus, OrderByType.Asc).OrderBy(x => x.CreateAt, OrderByType.Desc).ToPageListAsync(inputDto.Current, inputDto.PageSize, total); + + + var sql = $@"SELECT a.Coupon_Id,a.SendNum,ISNULL(b.GetNum) as GetNum from + (SELECT Coupon_Id,sum(SendNum) as SendNum from BPA_CouponRange GROUP BY Coupon_Id) as a + LEFT JOIN(SELECT Coupon_Id, count(*) as GetNum from BPA_CustomerCoupon GROUP BY Coupon_Id ) + as b on a.Coupon_Id = b.Coupon_Id where a.Coupon_Id in({string.Join(",", data.Select(x => "'" + x.Id + "'"))})"; + if (data.Count>0) + { + obj = await db.SqlQueryable(sql).ToListAsync(); + } + + result = data.Adapt>(); + foreach (var item in result) + { + var entity = obj.FirstOrDefault(x => x.Coupon_Id == item.Id); + if (entity != null) + { + item.SendNum = entity.SendNum; + item.GetNum = entity.GetNum; + item.IsAllowUpdate = false; + + } + else + { + item.IsAllowUpdate = true; + } + + } + return new PageUtil + { + Total = total, + Data = result + }; + } + + /// + /// 作废优惠卷 + /// + /// + /// + public async Task AbolishCoupon(string Id) + { + + + try + { + db.BeginTran(); + var result = false; + var f1 = true; + var by = App.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value; + var couponRangeIdList = db.Queryable().Where(x => x.Coupon_Id == Id).Select(x => x.Id).ToList(); + if (couponRangeIdList.Count > 0) + { + f1 = db.Updateable(t => new BPA_CouponRangeRelations() { Status = 0 }) + .Where(t => couponRangeIdList.Contains(t.Coupon_Range_Id)).ExecuteCommandHasChange(); + db.Updateable(t => new BPA_CouponGoodsRelations() { Status = 0 }) + .Where(t => couponRangeIdList.Contains(t.Coupon_Range_Id)).ExecuteCommandHasChange(); + } + if (f1) + { + result = db.Updateable().SetColumns(it => + new BPA_Coupon() { ValidStatus = 3, UpdateAt = DateTime.Now, UpdateBy = by }).Where(it => it.Id == Id).ExecuteCommandHasChange(); + } + db.CommitTran(); + return result; + } + catch (Exception ex) + { + db.RollbackTran(); + //BPALog.WriteLog(msg + ":" + ex.Message, LogEnum.Error, null, ex); + throw Oops.Oh("作废优惠卷"+ex.Message); + } + } + + + /// + /// 新增优惠卷 + /// + /// + /// + public async Task AddCoupon(CouponBasetDto inputDto) + { + if (inputDto.TimeType == 1 && inputDto.ValidEndTime < inputDto.ValidStartTime) + { + throw Oops.Oh("开始时间不能大于结束时间"); + } + inputDto.Id = Guid.NewGuid().ToString(); + inputDto.CreateAt = DateTime.Now; + inputDto.CreateBy = App.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value; + inputDto.CreateType = Convert.ToInt32(App.User.FindFirst(ClaimConst.LoginType)?.Value); + var result = await db.Insertable(inputDto.Adapt()).ExecuteCommandAsync(); + + return await Task.FromResult(result > 0); + } + + /// + /// 删除优惠卷 + /// + /// + /// + public async Task DeleteCoupon(List Ids) + { + + try + { + db.BeginTran(); + var couponRangeIdList = db.Queryable().Where(x => Ids.Contains(x.Coupon_Id)).Select(x => x.Id).ToList(); + if (couponRangeIdList.Count > 0) + { + db.Updateable(t => new BPA_CouponRangeRelations() { Status = CommonStatus.DISABLE }) + .Where(t => couponRangeIdList.Contains(t.Coupon_Range_Id)) + .ExecuteCommandHasChange(); + db.Updateable(t => new BPA_CouponGoodsRelations() { Status = CommonStatus.DISABLE }) + .Where(t => couponRangeIdList.Contains(t.Coupon_Range_Id)) + .ExecuteCommandHasChange(); + } + var deleteBy = App.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value; + var result = db.Updateable().SetColumns(it => new BPA_Coupon + { + IsDeleted = 1, + DeleteAt = DateTime.Now, + DeleteBy = deleteBy + }).Where(it => Ids.Contains(it.Id)).ExecuteCommandAsync(); + db.CommitTran(); + return result.Result > 0; + } + catch (Exception ex) + { + db.RollbackTran(); + //BPALog.WriteLog(msg + ":" + ex.Message, LogEnum.Error, null, ex); + throw Oops.Oh(ex.Message); + } + } + + /// + /// 修改优惠卷 + /// + /// + /// + public async Task UpdateCoupon([FromBody] CouponBasetDto inputDto) + { + if (inputDto.TimeType == 1 && inputDto.ValidEndTime < inputDto.ValidStartTime) + { + throw Oops.Oh("开始时间不能大于结束时间"); + } + //这个需要改 + var data = db.Queryable().Where(x => x.Coupon_Id == inputDto.Id).Any(); + if (!data) + { + inputDto.UpdateAt = DateTime.Now; + inputDto.UpdateBy = App.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value; + var result = db.Updateable(inputDto.Adapt()).IgnoreColumns(it => + new { it.CreateType, it.CreateAt, it.CreateBy, it.DeleteAt, it.DeleteBy, it.IsDeleted }).ExecuteCommand(); + return await Task.FromResult(result > 0); + } + else + { + throw Oops.Oh($"卷以分发,修改失败"); + } + + } + + /// + /// 修改优惠券状态 + /// + /// + /// + public async Task UpdateCouponStatus([FromBody] CouponBasetDto inputDto) + { + var result = await db.Updateable(inputDto.Adapt()).UpdateColumns(it => + new { it.ValidStatus }).ExecuteCommandAsync(); + return await Task.FromResult(result > 0); + + } + + + /// + /// 优惠券领取信息(分页) + /// + /// + /// + public async Task GetCustomerPage(CustomerCouponPageExDto input) + { + var total = new RefAsync(); + + var vvv = await db.Queryable((t, x, y) => new JoinQueryInfos(JoinType.Inner, t.Coupon_Id == x.Id, JoinType.Inner, t.Coupon_Range_Id == y.Id)).ToListAsync(); + + + var res = await db.Queryable((t, x, y) => new JoinQueryInfos(JoinType.Inner, t.Coupon_Id == x.Id, JoinType.Inner, t.Coupon_Range_Id == y.Id)) + .WhereIF(!string.IsNullOrEmpty(input.BatchNo), (t, x, y) => y.BatchNo == input.BatchNo) + .WhereIF(!string.IsNullOrEmpty(input.CouponTitle), (t, x) => x.CouponTitle.Contains(input.CouponTitle)) + .WhereIF(input.State is < 4, t => t.State == input.State.Value) + .WhereIF(input.State is 4, t => t.Valid_EndTime < DateTime.Now && t.State == 1) + .WhereIF(!string.IsNullOrEmpty(input.CustomerPhone), t => t.CustomerPhone.Contains(input.CustomerPhone)) + .WhereIF(!string.IsNullOrEmpty(input.OrderId), t => t.Order_Id.Contains(input.OrderId)) + .WhereIF(input.ReceiveType.HasValue, t => t.Receive_Type == input.ReceiveType.Value) + .WhereIF(input.WriteOffTime.HasValue, t => t.WriteOffTime >= input.WriteOffTime.Value && t.WriteOffTime < DateTime.Parse($"{input.WriteOffTime:yyyy-MM-dd 23:59:59}")) + .WhereIF(input.CreateAt.HasValue, t => t.CreateAt >= input.CreateAt.Value && t.CreateAt < DateTime.Parse($"{input.CreateAt:yyyy-MM-dd 23:59:59}")) + .Select((t, x, y) => new CustomerCouponPageResultOutputDto + { + CustomerId = t.Customer_Id, + Id = t.Id==null?"":t.Id, + OrderId = t.Order_Id, + ReceiveType = t.Receive_Type, + State = t.State, + CouponTitle = x.CouponTitle, + RangeType = y.RangeType, + ValidEndTime = t.Valid_EndTime, + ValidStartTime = t.Valid_StartTime, + WriteOffTime = t.WriteOffTime, + CreateAt = t.CreateAt==null?Convert.ToDateTime("2000-01-01"): t.CreateAt, + Phone = t.CustomerPhone + }).OrderBy(t => t.CreateAt, OrderByType.Desc) + .ToPageListAsync(input.Current, input.PageSize, total); + var Ids = res.Select(t => t.Id).ToList(); + var storeIds = db.Queryable().Where(t => Ids.Contains(t.Coupon_Customer_Id)).Select(t => t.StoreId).ToList(); + foreach (var item in res) + { + item.StoreName = string.Join(",", db.Queryable().Where(t => t.IsDeleted == 0).Where(t => storeIds.Contains(t.Id)).Select(t => t.Name).ToList()); + + + if (DateTime.Now > item.ValidEndTime && item.State == 1) + item.State = 4; + } + return new PageUtil { Data = res, Total = total }; + } + + #endregion + + #region 领券 + + /// + /// 指定客户 + /// + /// + /// + public async Task ReceiveCouponByInput(CustomerCouponInputDto input) + { + + try + { + db.BeginTran(); + foreach (var item in input.MemberId) + { + var result = _couponHelperServices.SendCoupon(input.CouponId, input.CouponRangeId, 1, item, input.CouponGitType.HasValue ? input.CouponGitType.Value : E_CouponGitType.指定领取, db).Result; + if (!result.IsSuccess) + { + throw Oops.Oh(item + ":" + result.Msg); + } + } + db.CommitTran(); + return true; + } + catch (Exception ex) + { + db.RollbackTran(); + //BPALog.WriteLog(msg + ":" + ex.Message, LogEnum.Error, null, ex); + throw Oops.Oh("发放优惠券到指定客户"+ex.Message); + } + } + + /// + /// 失效顾客优惠券(作废用户领取的优惠券) + /// + /// + public async Task AbolishCustomerCoupon(string Id) + { + + try + { + db.BeginTran(); + var res= db.Updateable() + .SetColumns(t => t.State == 4) + .Where(t => t.IsDeleted == 0) + .Where(t => t.Id == Id) + .ExecuteCommandHasChange(); + db.CommitTran(); + return await Task.FromResult(res); + } + catch (Exception ex) + { + db.RollbackTran(); + //BPALog.WriteLog(msg + ":" + ex.Message, LogEnum.Error, null, ex); + throw Oops.Oh(ex.Message); + } + } + + #endregion + + #region 对外暴露接口-小程序 + /// + /// 领券(支持批量领取) + /// + /// + /// + public async Task ReceiveCoupon(List input) + { + + try + { + db.BeginTran(); + var entity = input.Adapt>(); + + foreach (var item in entity) + { + var result = _couponHelperServices.SendCoupon(item.Coupon_Id, item.Coupon_Range_Id, 1, item.Coupon_Id, E_CouponGitType.指定领取, db).Result; + if (!result.IsSuccess) + { + throw Oops.Oh(item + ":" + result.IsSuccess); + } + }; + db.CommitTran(); + return true; + } + catch (Exception ex) + { + db.RollbackTran(); + //BPALog.WriteLog(msg + ":" + ex.Message, LogEnum.Error, null, ex); + throw Oops.Oh(ex.Message); + } + } + + + /// + /// 退单返还优惠卷 + /// + /// + public async Task RebackCoupon(string OrderId) + { + try + { + db.BeginTran(); + var customerCoupon = db.Queryable() + .Where(t => t.Order_Id == OrderId) + .Where(t => t.State == 3 || t.State == 2).First(); + if (customerCoupon == null) + { + return new ResultEntity { Msg = "当前订单未使用优惠券", IsSuccess = false }; + } + customerCoupon.State = 1; + + BPA_CouponLog Log = new BPA_CouponLog + { + Id = Guid.NewGuid().ToString(), + CouponId = customerCoupon.Coupon_Id, + CustomerId = customerCoupon.Customer_Id, + OrderId = OrderId, + OrderType = 0, + Coupon_Customer_Id = customerCoupon.Id, + Remark = $"客户【{customerCoupon.Customer_Id}】退单【{OrderId}】补券【{customerCoupon.Coupon_Id}】类型【退单补券】", + OrderTime = DateTime.Now + }; + db.Insertable(Log).ExecuteCommand(); + var r = db.Updateable(customerCoupon).ExecuteCommandHasChange(); + db.CommitTran(); + return new ResultEntity { Msg = string.Empty, IsSuccess = r }; + } + catch (Exception ex) + { + db.RollbackTran(); + //BPALog.WriteLog(msg + ":" + ex.Message, LogEnum.Error, null, ex); + throw Oops.Oh("退单返还优惠卷服务器异常,请检查参数"+ex.Message); + } + } + + + /// + /// 查看领取的优惠券 + /// + /// + /// + public async Task WacthCoupon(CustomerCouponPageDto input) + { + var total = new RefAsync(); + var data = await db.Queryable((t, x) => t.Coupon_Id == x.Id) + .Where(t => t.IsDeleted == 0) + .Where(t => t.State == (input.State.Value==4?1: input.State)) + .WhereIF(input.State != null && input.State.Value ==4,(t,x)=>t.Valid_EndTime t.Valid_EndTime > DateTime.Now) + // .Where((t, x) => x.ValidStatus == 1) + .Where(t => t.CustomerPhone == input.CustomerPhone || t.Customer_Id == input.CustomerId) + .Select((t, x) => new CustomerCouponOutputDto + { + CustomerId = t.Customer_Id, + CouponTitle = x.CouponTitle, + CouponId = t.Coupon_Id, + Id = t.Id, + State = t.State, + CouponRangeId = t.Coupon_Range_Id, + OrderId = t.Order_Id, + ReceiveType = t.Receive_Type, + ValidStartTime = t.Valid_StartTime, + ValidEndTime = t.Valid_EndTime, + CouponValue = x.CouponValue, + Condition = x.Condition + }).ToPageListAsync(input.Current, input.PageSize, total); + return new PageUtil + { + Data = data, + Total = total + }; + } + + /// + /// 查询可以用券 + /// + /// + /// + public async Task> SelectCanUseCoupon(CustomerCouponCanUseDto input) + { + var groupId = App.User?.FindFirst(ClaimConst.GroupId)?.Value; + StringBuilder sb = new StringBuilder(); + sb.Append($@"SELECT + a.Customer_Id AS CustomerId, + b.CouponTitle, + a.Coupon_Id AS CouponId, + a.Id, + a.State, + a.Coupon_Range_Id AS CouponRangeId, + a.Order_Id AS OrderId, + a.ReceiveType, + b.CouponValue, + b.Condition, + a.ValidStartTime AS ValidStartTime, + a.ValidEndTime AS ValidEndTime, + b.Remarks as Remark + FROM + BPA_CustomerCoupon AS a + JOIN BPA_Coupon AS b ON a.Coupon_Id= b.Id + JOIN BPA_CouponRange AS c ON a.Coupon_Range_Id= c.Id + WHERE + a.Customer_Id= '{input.CustomerId}' + AND a.State=1 AND b.ValidStatus=1 AND a.IsDeleted=0 and a.ValidEndTime>='{DateTime.Now}'"); + + + if (input.StoreId.Count() > 0) + sb.Append($@" and ( a.Coupon_Range_Id in (SELECT Coupon_Range_Id from BPA_CouponRangeRelations WHERE Status=0 and RangeTypeId in + ('{string.Join("','", input.StoreId)}') )) "); + + if (input.TotalPrice.HasValue) + sb.Append($@" AND b.Condition<= {input.TotalPrice}"); + var sql = sb.ToString(); + + + var data = await db.SqlQueryable(sql).ToListAsync(); + + + if (input.GoodsId.Count() > 0) + { + //查询有限定食物的批次 + var goodsRelations = db.SqlQueryable($@"SELECT * from BPA_CouponGoodsRelations where Coupon_Range_Id in('{string.Join("','", data.Select(x => x.CouponRangeId).ToList())}') ").ToList(); + + //排除满足条件的 + var ids = new List(); + foreach (var item in goodsRelations.GroupBy(x => x.Coupon_Range_Id)) + { + var isAdd = true; + foreach (var item2 in item) + { + if (input.GoodsId.Contains(item2.GoodsId)) + { + isAdd = false; + break; + } + } + if (isAdd) + { + ids.Add(item.Key); + } + } + + data = data.Where(x => !ids.Contains(x.CouponRangeId)).ToList(); + } + return data; + } + + + /// + /// 查询领取详情 + /// + /// + /// + public async Task CustomerCouponDetail(string Id) + { + var data = await db.Queryable((t, x) => t.Coupon_Id == x.Id).Where(t => t.Id == Id) + .Select((t, x) => new CustomerCouponOutputDto + { + CustomerId = t.Customer_Id, + CouponTitle = x.CouponTitle, + CouponId = t.Coupon_Id, + Id = t.Id, + State = t.State, + CouponRangeId = t.Coupon_Range_Id, + OrderId = t.Order_Id, + ReceiveType = t.Receive_Type, + ValidStartTime = t.Valid_StartTime, + ValidEndTime = t.Valid_EndTime, + Condition = x.Condition, + CouponValue = x.CouponValue, + WriteOffTime = t.WriteOffTime, + Remark = x.Remarks, + CouponType = x.CouponType + }).FirstAsync(); + + if (data == null) return null; + var RangeType = db.Queryable().First(t => t.Id == data.CouponRangeId).RangeType; + var RangeTypeIds = db.Queryable().Where(t => t.Status == CommonStatus.ENABLE) + .Where(t => t.Coupon_Range_Id == data.CouponRangeId).Select(t => t.RangeTypeId).ToList(); + var RangeGoodIds = db.Queryable().Where(t => t.Status == CommonStatus.ENABLE) + .Where(t => t.Coupon_Range_Id == data.CouponRangeId).Select(t => t.GoodsId).ToList(); + if (RangeType == 1) + { + data.RangeTypeStr = "适用店铺"; + var Names = db.Queryable().Where(t => t.IsDeleted == 0).Where(t => RangeTypeIds.Contains(t.Id)).Select(t => t.Name).ToList(); + data.UseRange = Names; + } + //if (RangeType == 2) + //{ + // data.RangeTypeStr = "适用供应商"; + // var Names = db.Queryable().Where(t => t.Status == 0).Where(t => t.IsDeleted == 0).Where(t => RangeTypeIds.Contains(t.Id)).Select(t => t.Name).ToList(); + // data.UseRange = Names; + //} + //if (RangeType == 3) + //{ + // data.RangeTypeStr = "适用区域"; + // var Names = db.Queryable().Where(t => t.IsDeleted == 0).Where(t => RangeTypeIds.Contains(t.Id)).Select(t => t.StoreType_Name).ToList(); + // data.UseRange = Names; + //} + if (RangeGoodIds.Count > 0) + { + var goodsData =await GetGoodsByMenuIdPage(new FoodMenu.Dtos.FoodMenuQueryInputDto() + { + Current=1, + PageSize=999999 + }); + + + //适用商品 + data.UseGoods = goodsData.Where(t => RangeGoodIds.Contains(t.id)).Select(t => t.name).ToList(); + } + data.Remarks = data.Remark?.Split(";").ToList(); + return data; + } + + /// + /// 优惠券的使用 + /// + /// false券无效或者失效或有错误 + public async Task CustomerCouponOff(CustomerCouponBaseDto input) + { + + try + { + db.BeginTran(); + + + BPA_CustomerCoupon entity = db.Queryable((t, a) => ( + new JoinQueryInfos(JoinType.Left, t.Coupon_Id == a.Id))) + .Where(t => t.Customer_Id == input.CustomerId) + .WhereIF(!string.IsNullOrEmpty(input.CouponId), t => t.Coupon_Id == input.CouponId) + .Where(t => t.Id == input.CustomerCouponId) + .Where(t => t.Valid_StartTime < input.OrderTime && t.Valid_EndTime >= input.OrderTime) + .Where((t, a) => t.State == 1 && a.ValidStatus == 1) + .Where(t => t.IsDeleted == 0) + .First(); + + if (entity == null) + { + return new CouponUseMsgDto { Msg = "无效优惠券", IsSuccess = false }; + } + if (entity.Valid_EndTime <= DateTime.Now) + { + return new CouponUseMsgDto { Msg = "优惠券已过期", IsSuccess = false }; + } + + + var data = _couponHelperServices.GetCouponUseScope(input.CustomerCouponId).Result; + //优惠券范围匹配 + + var couponUseScope = data.Data as CouponUseScopeOutDto; + + foreach (var item in input.StoreId) + { + + if (!couponUseScope.StoreList.Select(x => x.Id).Contains(item)) + { + return new CouponUseMsgDto { Msg = "使用店铺或区域不匹配", IsSuccess = false }; + } + } + entity.Order_Id = input.OrderId; + entity.State = (int)input.UseType; + entity.UpdateAt = DateTime.Now; + + var ret = db.Updateable(entity).ExecuteCommandHasChange(); + List storeLinks = new List(); + input.StoreId.ForEach(t => + { + BPA_CouponCustomerStore storeLink = new BPA_CouponCustomerStore + { + Id = Guid.NewGuid().ToString(), + Coupon_Customer_Id = entity.Id, + StoreId = t + }; + storeLinks.Add(storeLink); + }); + db.Insertable(storeLinks).ExecuteCommand(); + BPA_CouponLog Log = new BPA_CouponLog + { + Id = Guid.NewGuid().ToString(), + CouponId = entity.Coupon_Id, + CustomerId = entity.Customer_Id, + OrderId = input.OrderId, + OrderType = 1, + Coupon_Customer_Id = entity.Id, + Remark = $"客户【{entity.Customer_Id}】下单【{input.OrderId}】用券【{entity.Coupon_Id}】类型【下单用券】", + OrderTime = input.OrderTime + }; + db.Insertable(Log).ExecuteCommand(); + db.CommitTran(); + return new CouponUseMsgDto { Msg = "", IsSuccess = true }; + } + catch (Exception ex) + { + db.RollbackTran(); + //BPALog.WriteLog(msg + ":" + ex.Message, LogEnum.Error, null, ex); + throw Oops.Oh(ex.Message); + } + } + + /// + /// 回调写入优惠券状态 + /// + /// + /// + /// + public async Task UpdateState(string OdrerId, int State) + { + try + { + db.BeginTran(); + var res= db.Updateable().SetColumns(t => t.State == State).Where(t => t.Order_Id == OdrerId).ExecuteCommandHasChange(); + db.CommitTran(); + return await Task.FromResult(res); + } + catch (Exception ex) + { + db.RollbackTran(); + //BPALog.WriteLog(msg + ":" + ex.Message, LogEnum.Error, null, ex); + throw Oops.Oh(ex.Message); + } + } + + /// + /// 查询流水日志 + /// + /// + public async Task> GetCouponLog(string CouponCustomerId) + { + return await db.Queryable((a, b, c) => new JoinQueryInfos( + JoinType.Inner, a.CouponId == b.Coupon_Id && a.Coupon_Customer_Id == b.Id, + JoinType.Inner, a.CouponId == c.Id + )).Where(a => a.Coupon_Customer_Id == CouponCustomerId).Select((a, b, c) => new CouponLogOutputDto + { + Id = a.Id, + CouponId = a.CouponId, + CouponTitle = c.CouponTitle, + CouponType = c.CouponType, + CouponValue = c.CouponValue, + CustomerId = b.Customer_Id, + Phone = b.CustomerPhone, + OrderId = a.OrderId, + OrderType = a.OrderType, + Remark = a.Remark, + OrderTime = a.OrderTime + }).ToListAsync(); + + } + + /// + /// 根据订单号获取用户的优惠券使用状态 + /// + /// + /// + public async Task> GetCouponStutasByOrderId(List OrderId) + { + var data = await db.Queryable((a, b) => a.Coupon_Id == b.Id).Where(a => a.IsDeleted == 0) + .Where(a => OrderId.Contains(a.Order_Id)).Select((a, b) => new CusomterCouponDTO + { + CouponId = b.Id, + CouponTitle = b.CouponTitle, + CustomerId = a.Id, + OpenId = a.Customer_Id, + OrderId = a.Order_Id, + Stutas = a.State + + }).ToListAsync(); + + return data; + } + + #endregion + + #region 发券记录(批次发券) + /// + /// 新增发券记录 + /// + /// + /// + public async Task AddCouponSendRecord(CouponRecordDto input) + { + var data = await _couponHelperServices.IsUseCouponCheck(input.Coupon_Id); + + if (!data.IsSuccess) + { + throw Oops.Oh($"优惠券不可用"); + } + + if (input.RangeType == 1) + { + var count = db.Queryable().Where(x => input.Relation.Contains(x.Id) && x.IsDeleted == 0 ).ToList(); + if (input.Relation.Count>0&& count.Count()<=0) + { + throw Oops.Oh($"店铺不合法"); + } + } + //else if (input.RangeType==3) + + //{ + // var count = NewSqlSugar.StaticContext().Queryable().Where(x => input.Relation.Contains(x.Id) && x.IsDeleted == 0 ).ToList(); + // if (input.Relation.Count > 0 && count.Count() <= 0) + // { + // throw Oops.Oh($"区域不合法"); + // } + + //} + + try + { + db.BeginTran(); + var entity = input.Adapt(); + entity.CreateType = Convert.ToInt32(App.User.FindFirst(ClaimConst.LoginType)?.Value); + entity.BatchNo = DateTime.Now.ToString("yyyyMMddHHmmssffff"); + var res = db.Insertable(entity).CallEntityMethod(t => t.Create()).ExecuteReturnEntity(); + List temp = new List(); + input.Relation.ForEach(t => + { + temp.Add(new BPA_CouponRangeRelations + { + Coupon_Range_Id = res.Id, + Status = CommonStatus.ENABLE, + RangeTypeId = t + }); + }); + List goods = new List(); + if (input.GoodsRelation != null && input.GoodsRelation.Count != 0) + { + input.GoodsRelation.ForEach(t => + { + goods.Add(new BPA_CouponGoodsRelations + { + Coupon_Range_Id = res.Id, + Status = CommonStatus.ENABLE, + GoodsId = t + }); + }); + db.Insertable(goods).CallEntityMethod(t => t.Create()).ExecuteCommand(); + } + var res1= db.Insertable(temp).CallEntityMethod(t => t.Create()).ExecuteCommand() > 0; + db.CommitTran(); + return await Task.FromResult(res1); + } + catch (Exception ex) + { + db.RollbackTran(); + //BPALog.WriteLog(msg + ":" + ex.Message, LogEnum.Error, null, ex); + throw Oops.Oh(ex.Message); + } + } + /// + /// 获取发券的管理记录 + /// + /// + /// + public async Task GetCouponRecordById(CouponRecordPageDto input) + { + var total = new RefAsync(); + var entity = await db.Queryable((a, b) => a.Id == b.Coupon_Range_Id) + .Where(a => a.IsDeleted == 0) + .Where(a => a.BatchNo == input.BatchNo) + .Where(a => a.Coupon_Id == input.CouponId) + .WhereIF(input.Status.HasValue && input.Status.Value != 2, (a, b) => b.Status == CommonStatus.ENABLE) + .WhereIF(input.RangeType.HasValue && input.RangeType.Value != 0, a => a.RangeType == input.RangeType.Value) + .OrderBy(a => a.CreateAt, OrderByType.Desc) + .Select((a, b) => new + { + Coupon_Id = a.Coupon_Id, + Id = b.Id, + RangeType = a.RangeType, + Status = b.Status, + Remark = b.Remark, + Relat = b.RangeTypeId, + SendTime = a.CreateAt==null? "": a.CreateAt.ToString(), + }).ToPageListAsync(input.Current, input.PageSize, total); + + List result = new List(); + foreach (var item in entity) + { + + CouponRecordDto dto = item.Adapt(); + + dto.Supplier = db.Queryable().Where(t => t.IsDeleted == 0).First(t => t.Id == item.Relat).Name; + + result.Add(dto); + } + return new PageUtil { Data = result, Total = total }; + } + /// + /// 获取发券的管理记录商品 + /// + /// + /// + public async Task GetCouponRecordGoods(CouponRecordPageDto input) + { + var total = new RefAsync(); + var entity = await db.Queryable((a, b) => a.Id == b.Coupon_Range_Id) + .Where(a => a.IsDeleted == 0) + .Where(a => a.BatchNo == input.BatchNo) + .Where(a => a.Coupon_Id == input.CouponId) + .WhereIF(input.Status.HasValue && input.Status.Value != 2, (a, b) => b.Status == CommonStatus.ENABLE) + .WhereIF(input.RangeType.HasValue && input.RangeType.Value != 0, a => a.RangeType == input.RangeType.Value) + .OrderBy(a => a.CreateAt, OrderByType.Desc) + .Select((a, b) => new + { + Coupon_Id = a.Coupon_Id, + Id = b.Id, + RangeType = a.RangeType, + Status = b.Status, + Remark = b.Remark, + Relat = b.GoodsId, + SendTime = a.CreateAt + }).ToPageListAsync(input.Current, input.PageSize, total); + + List result = new List(); + foreach (var item in entity) + { + var goodsData = await GetGoodsByMenuIdPage(new FoodMenu.Dtos.FoodMenuQueryInputDto() + { + Current = 1, + PageSize = 999999 + }); + + + CouponRecordDto dto = item.Adapt(); + dto.Supplier = goodsData.First(t => t.id == item.Relat)?.name; + result.Add(dto); + } + return new PageUtil { Data = result, Total = total }; + } + /// + /// 记录汇总 + /// + /// + /// + public async Task GetCouponRecordPage(CouponRecordPageDto input) + { + var total = new RefAsync(); + + var data = await db.Queryable((t, x, y) => + new JoinQueryInfos( + JoinType.Left, t.Coupon_Id == x.Coupon_Id && t.Id == x.Coupon_Range_Id, + JoinType.Left, t.Coupon_Id == y.Id)) + .WhereIF(input.CreateAt.HasValue, t => t.CreateAt.Date == input.CreateAt.Value.Date) + .WhereIF(input.RangeType.HasValue, t => t.RangeType == input.RangeType.Value) + .WhereIF(!string.IsNullOrEmpty(input.CouponTitle), (t, x, y) => y.CouponTitle.Contains(input.CouponTitle)) + .WhereIF(!string.IsNullOrEmpty(input.BatchNo), (t, x, y) => t.BatchNo.Contains(input.BatchNo)) + .OrderBy((t, x, y) => y.ValidStatus) + .OrderBy((t, x, y) => t.SendNum - SqlFunc.AggregateCount(x.Id), OrderByType.Desc) + .OrderBy((t, x, y) => t.CreateAt, OrderByType.Desc) + .GroupBy((t, x, y) => new + { + t.RangeType, + t.Id, + t.SendNum, + t.Coupon_Id, + y.CouponTitle, + t.CreateAt, + t.BatchNo, + t.Remark, + y.ValidStatus + }).Select((t, x, y) => new + { + t.RangeType, + t.Id, + y.CouponTitle, + t.SendNum, + CreateAt=t.CreateAt==null?"": t.CreateAt.ToString(), + t.BatchNo, + t.Remark, + CouponId = t.Coupon_Id, + TotalNum = SqlFunc.AggregateCount(x.Id), + LastNum = t.SendNum - SqlFunc.AggregateCount(x.Id), + y.ValidStatus + }) + .ToPageListAsync(input.Current, input.PageSize, total); + return new PageUtil + { + Total = total, + Data = data + }; + } + /// + /// 召回禁用优惠卷 + /// + /// + /// + public async Task RecallCoupon(CouponRecordDto input) + { + try + { + db.BeginTran(); + var res= db.Updateable(t => new BPA_CouponRangeRelations() { Status = (CommonStatus)input.Status, Remark = input.Remark }) + .Where(t => t.Id == input.Id) + .ExecuteCommandHasChange(); + db.CommitTran(); + return await Task.FromResult(res); + } + catch (Exception ex) + { + db.RollbackTran(); + //BPALog.WriteLog(msg + ":" + ex.Message, LogEnum.Error, null, ex); + throw Oops.Oh(ex.Message); + } + } + + /// + /// 召回禁用优惠卷商品 + /// + /// + /// + public async Task RecallCouponGoods(CouponRecordDto input) + { + try + { + db.BeginTran(); + var res= db.Updateable(t => new BPA_CouponGoodsRelations() { Status = CommonStatus.ENABLE, Remark = input.Remark }) + .Where(t => t.Id == input.Id) + .ExecuteCommandHasChange(); + db.CommitTran(); + return await Task.FromResult(res); + } + catch (Exception ex) + { + db.RollbackTran(); + //BPALog.WriteLog(msg + ":" + ex.Message, LogEnum.Error, null, ex); + throw Oops.Oh(ex.Message); + } + } + + #endregion + + + /// + /// 获取菜品列表 + /// + /// + /// + public async Task> GetGoodsByMenuIdPage(FoodMenuQueryInputDto inputDto) + { + var headers = _httpContextAccessor.HttpContext.Request.Headers; + var authorization = headers["Authorization"]; + + Dictionary dic = new Dictionary(); + dic.Add("Authorization", authorization); + //var url1 = App.Configuration["SAAS_Manage"] + "/api/goods/getgoodslist"; + //var json1 = HttpHelper.HttpGet(url1, "", dic, ""); + + var url = App.Configuration["SAAS_Manage"] + "api/goods/page"; + var json2 = HttpHelper.PostData(url, JsonConvert.SerializeObject(new + { + current = inputDto.Current, + pageSize = inputDto.PageSize, + name = inputDto.Name, + + }), Encoding.UTF8, "application/json", dic); + + var data = JsonConvert.DeserializeObject(json2); + return data.data.data; + } + + /// + /// 获取商品类型 + /// + /// + public async Task> GetGoodsTypeList() + { + var headers = _httpContextAccessor.HttpContext.Request.Headers; + var authorization = headers["Authorization"]; + + Dictionary dic = new Dictionary(); + dic.Add("Authorization", authorization); + //var url1 = App.Configuration["SAAS_Manage"] + "/api/goods/getgoodslist"; + //var json1 = HttpHelper.HttpGet(url1, "", dic, ""); + + var url = App.Configuration["SAAS_Manage"] + "api/goodstype/tree"; + var json2 = HttpHelper.HttpGet(url, "", dic, "application/json"); + + var data = JsonConvert.DeserializeObject(json2); + return data.data; + } + + + /// + /// 获取商品类型 + /// + /// + public async Task> GetGoodsType() + { + var data = await GetGoodsTypeList(); + + return data.ToDictionary(t => t.key, t => t.title); + } + + /// + /// 获取商品 + /// + /// + /// + public async Task> GetGoods(string GoodsTypeId) + { + var goodsData = await GetGoodsByMenuIdPage(new FoodMenu.Dtos.FoodMenuQueryInputDto() + { + Current = 1, + PageSize = 999999 + }); + + //商品 + return goodsData.WhereIF(GoodsTypeId != "-1", t => t.goodsTypeId == GoodsTypeId) + .ToDictionary(t => t.id, t => t.name); + } + + /// + /// 获取会员信息 + /// + /// + /// + public async Task> GetCustomerInfo(CustomerInfoInputDto input) + { + + return await db.Queryable().Where(t => !SqlFunc.IsNullOrEmpty(t.Phone)) + .WhereIF(!string.IsNullOrEmpty(input.Phone), t => t.Phone.Contains(input.Phone)).Select(t => new MemberInfoOutputDto + { + Phone = t.Phone, + MemberId = t.Id + }).ToListAsync(); + + + } + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/BaseResultGoodsTypeDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/BaseResultGoodsTypeDto.cs new file mode 100644 index 0000000..5941590 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/BaseResultGoodsTypeDto.cs @@ -0,0 +1,41 @@ +using BPA.KitChen.StoreManagement.Application.Service.ShopManage.FoodMenu.Dtos; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.CouponServices.Dtos +{ + public class BaseResultGoodsTypeDto + { + public int statusCode { get; set; } + + public List data { get; set; } + + public string succeeded { get; set; } + + public string errors { get; set; } + + public string extras { get; set; } + + public int timestamp { get; set; } + } + + public class GoodsTypeDataItem + { + public int type { get; set; } + + public string key { get; set; } + + public string parentId { get; set; } + + public string title { get; set; } + + public string value { get; set; } + + public int weight { get; set; } + + public List children { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/Class1.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/Class1.cs new file mode 100644 index 0000000..0270ddd --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/Class1.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.CouponServices.Dtos +{ + internal class Class1 + { + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/CouponBasetDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/CouponBasetDto.cs new file mode 100644 index 0000000..7736b78 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/CouponBasetDto.cs @@ -0,0 +1,106 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.CouponServices.Dtos +{ + /// + /// 优惠卷基础信息 + /// + public class CouponBasetDto + { + /// + /// Id + /// + public string Id { get; set; } + /// + /// 优惠券标题 + /// + [Required] + public string CouponTitle { get; set; } + /// + /// 优惠券类型(1.满减优惠卷 2.代金优惠卷 3.无门槛优惠卷) + /// + [Range(1, 3, ErrorMessage = "优惠卷类型错误")] + public int CouponType { get; set; } + /// + /// 优惠券值(优惠金额) + /// + public decimal CouponValue { get; set; } + /// + /// 使用条件 + /// + public decimal Condition { get; set; } + /// + /// 使用时间的类型 1.时间范围内 2.固定期限 + /// + [Range(1, 2, ErrorMessage = "时间类型错误")] + public int TimeType { get; set; } + /// + /// 固定期限值(如领取后10内有效) + /// + public int ValidFixedTerm { get; set; } + /// + /// 开始时间 + /// + public DateTime ValidStartTime { get; set; } + /// + /// 结束时间 + /// + public DateTime ValidEndTime { get; set; } + /// + /// 状态(1:生效、2:失效 3:作废) + /// + [Range(1, 4, ErrorMessage = "状态错误")] + public int ValidStatus { get; set; } + /// + /// 每人可领取数量 + /// + [Range(0,999999)] + public int GetLimit { get; set; } + /// + /// 备注 + /// + public string Remarks { get; set; } + /// + /// 是否删除 + /// + public int IsDeleted { get; set; } + /// + /// 创建时间 + /// + public DateTime CreateAt { get; set; } + /// + /// 创建人 + /// + public string CreateBy { get; set; } + /// + /// 修改时间 + /// + public DateTime UpdateAt { get; set; } + /// + /// 修改人 + /// + public string UpdateBy { get; set; } + /// + /// 删除时间 + /// + public DateTime DeleteAt { get; set; } + /// + /// 删除人 + /// + public string DeleteBy { get; set; } + /// + /// 创建人类型(0.供应商 1.平台 ) + /// + public int CreateType { get; set; } + + public bool IsAllowUpdate { get; set; } + public int SendNum { get; set; } + public int GetNum { get; set; } + + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/CouponCanNumAndSendNum.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/CouponCanNumAndSendNum.cs new file mode 100644 index 0000000..8168b39 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/CouponCanNumAndSendNum.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.CouponServices.Dtos +{ + public class CouponCanNumAndSendNum + { + public string Coupon_Id { get; set; } + public int SendNum { get; set; } + public int GetNum { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/CouponLogDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/CouponLogDto.cs new file mode 100644 index 0000000..0766ff1 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/CouponLogDto.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.CouponServices.Dtos +{ + public class CouponLogOutputDto + { + /// + /// 主键 + /// + public string Id { get; set; } + /// + /// 订单Id + /// + public string OrderId { get; set; } + /// + /// 客户Id -- 微信的OpenId + /// + public string CustomerId { get; set; } + /// + /// 客户手机 + /// + public string Phone { get; set; } + /// + /// 0表示退单反券 1表示订单完成 + /// + public int OrderType { get; set; } + /// + /// 订单流转 + /// + public string OrderTypeStr => OrderType == 0 ? "退单反券" : "订单完成"; + /// + /// 券Id + /// + public string CouponId { get; set; } + /// + /// 备注 + /// + public string Remark { get; set; } + /// + /// 优惠券标题 + /// + public string CouponTitle { get; set; } + /// + /// 优惠券券值 + /// + public decimal CouponValue { get; set; } + /// + /// 类型 + /// + [Newtonsoft.Json.JsonIgnore] + public int? CouponType { get; set; } + /// + /// 优惠券类型 + /// + public string CouponTypeStr => !CouponType.HasValue ? "" : (CouponType == 1 ? "满减优惠卷" : (CouponType == 2 ? "代金优惠卷" : "无门槛优惠卷")); + /// + /// 订单时间 + /// + public DateTime OrderTime { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/CouponRecordDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/CouponRecordDto.cs new file mode 100644 index 0000000..011a57c --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/CouponRecordDto.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.CouponServices.Dtos +{ + public class CouponRecordDto + { + /// + /// 主键 + /// + public string Id { get; set; } + /// + /// 发放时间 + /// + public DateTime SendTime { get; set; } + /// + /// 发放数量 + /// + [Range(0, int.MaxValue)] + public int SendNum { get; set; } + /// + /// 优惠券Id + /// + public string Coupon_Id { get; set; } + /// + /// 适用范围类型 1.店铺 2.供应商 3.区域 + /// + public int RangeType { get; set; } + /// + /// 是否启用 0 禁用 1.启用 + /// + [Range(0, 1, ErrorMessage = "状态错误")] + public int Status { get; set; } + /// + /// 备注 + /// + public string Remark { get; set; } + /// + /// 店铺区域或供应商管理关系 + /// + public List Relation { get; set; } + /// + /// 商品Id + /// + public List GoodsRelation { get; set; } + /// + /// 区域 或者 供应商 或者店铺名称 + /// + public string Supplier { get; set; } + } + +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/CouponRecordPageDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/CouponRecordPageDto.cs new file mode 100644 index 0000000..62b3a4d --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/CouponRecordPageDto.cs @@ -0,0 +1,37 @@ +using BPA.KitChen.StoreManagement.Application.BaseDto; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.CouponServices.Dtos +{ + public class BasicDto : PageInputBase + { + /// + /// 适用范围类型 1.店铺 2.供应商 3.区域 + /// + public int? RangeType { get; set; } + } + public class CouponRecordPageDto : BasicDto + { + + /// + /// 是否启用 0 禁用 1.启用 + /// + public int? Status { get; set; } + /// + /// 优惠卷Id + /// + public string CouponId { get; set; } + /// + /// 批次号 + /// + public string? BatchNo { get; set; } + + public string CouponTitle { get; set; } + + public DateTime? CreateAt { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/CouponUseMsgDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/CouponUseMsgDto.cs new file mode 100644 index 0000000..b26482e --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/CouponUseMsgDto.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.CouponServices.Dtos +{ + public class CouponUseMsgDto + { + /// + /// 是否成功 + /// + public bool IsSuccess { get; set; } + /// + /// 消息 + /// + public string Msg { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/CustomerCouponBaseDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/CustomerCouponBaseDto.cs new file mode 100644 index 0000000..c8e4d7b --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/CustomerCouponBaseDto.cs @@ -0,0 +1,54 @@ +using BPA.Kitchen.Core.Common; +using BPA.KitChen.StoreManagement.Application.BaseDto; +using BPA.KitChen.StoreManagement.Core.Enum; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.CouponServices.Dtos +{ + public class CustomerCouponBaseDto + { + /// + /// 顾客优惠劵Id + /// + [Required] + public string CustomerCouponId { get; set; } + /// + /// 订单Id + /// + [Required] + public string OrderId { get; set; } + /// + /// 优惠券Id + /// + public string CouponId { get; set; } + /// + /// 客户Id + /// + public string CustomerId { get; set; } + /// + /// 店铺Id + /// + [Required] + public List StoreId { get; set; } + /// + /// 商品Id + /// + public List GoodsId { get; set; } + /// + /// 优惠券状态 + /// + [Required] + [CustomValidation(typeof(DtoValidator), "CouponUseType")] + public CouponUseType UseType { get; set; } + /// + /// 下单时间 + /// + [Required] + public DateTime OrderTime { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/CustomerCouponDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/CustomerCouponDto.cs new file mode 100644 index 0000000..d9360fc --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/CustomerCouponDto.cs @@ -0,0 +1,75 @@ + +using BPA.KitChen.StoreManagement.Core.Enum; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.CouponServices.Dtos +{ + public class CustomerCouponDto + { + /// + /// 客户Id + /// + public string Customer_Id { get; set; } + /// + /// 订单Id + /// + public string Order_Id { get; set; } + /// + /// 领取方式(1.小程序领取 2.线下门店扫码 3.活动自动下发 4.好友分享领取) + /// + public int Receive_Type { get; set; } + /// + /// 优惠券Id + /// + public string Coupon_Id { get; set; } + /// + /// 店铺Id 领券的时候不用填写 + /// + public string Store_Id { get; set; } + /// + /// 状态(1:未使用 2.已核销 3.占用中 4.失效)领取的时候不填写 + /// + public int State { get; set; } + /// + /// 开始时间 + /// + public DateTime Valid_StartTime { get; set; } + /// + /// 结束时间 + /// + public DateTime Valid_EndTime { get; set; } + /// + /// 核销时间 + /// + public DateTime? WriteOffTime { get; set; } + /// + /// 范围Id + /// + public string Coupon_Range_Id { get; set; } + /// + /// 用户手机号 + /// + public string CustomerPhone { get; set; } + } + public class CustomerCouponInputDto + { + /// + /// 客户Id + /// + public List MemberId { get; set; } + /// + /// 优惠卷Id + /// + public string CouponId { get; set; } + /// + /// 范围ID(批次号信息) + /// + public string CouponRangeId { get; set; } + + public E_CouponGitType? CouponGitType { get; set; } = E_CouponGitType.指定领取; + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/CustomerCouponOutputDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/CustomerCouponOutputDto.cs new file mode 100644 index 0000000..8ae1fb8 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/CustomerCouponOutputDto.cs @@ -0,0 +1,148 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.CouponServices.Dtos +{ + public class CustomerCouponOutputDto + { + public string Id { get; set; } + /// + /// 优惠券名称 + /// + public string CouponTitle { get; set; } + /// + /// 优惠券值(优惠金额) + /// + public decimal CouponValue { get; set; } + /// + /// 使用条件 + /// + public decimal Condition { get; set; } + /// + /// 客户Id + /// + public string CustomerId { get; set; } + /// + /// 订单Id + /// + public string OrderId { get; set; } + /// + /// 领取方式(1.小程序领取 2.线下门店扫码 3.活动自动下发 4.好友分享领取 5.指定发放) + /// + public int ReceiveType { get; set; } + /// + /// 优惠券Id + /// + public string CouponId { get; set; } + /// + /// 店铺Id + /// + public string StoreId { get; set; } + /// + /// 状态(1:未使用 2.已核销 3.占用中 4.失效) + /// + public int State { get; set; } + /// + /// 开始时间 + /// + public DateTime ValidStartTime { get; set; } + + /// + /// 结束时间 + /// + public DateTime ValidEndTime { get; set; } + /// + /// 核销时间 + /// + public DateTime? WriteOffTime { get; set; } + /// + /// 范围Id + /// + public string CouponRangeId { get; set; } + /// + /// 备注 + /// + public string Remark { get; set; } + /// + /// 备注 + /// + public List Remarks { get; set; } + /// + /// 类型 + /// + [Newtonsoft.Json.JsonIgnore] + public int? CouponType { get; set; } + /// + /// 优惠券类型 + /// + public string CouponTypeStr => !CouponType.HasValue ? "" : (CouponType == 1 ? "满减优惠卷" : (CouponType == 2 ? "代金优惠卷" : "无门槛优惠卷")); + /// + /// 适用条件 + /// + public string ConditionStr => !CouponType.HasValue ? "" : (CouponType == 1 ? $"满{Condition}元减{CouponValue}元" : (CouponType == 2 ? $"可抵扣{CouponValue}元" : "无门槛优惠卷")); + /// + /// 适用范围 + /// + public List UseRange { get; set; } + /// + /// 适用商品 + /// + public List UseGoods { get; set; } + /// + /// 适用范围 + /// + public string RangeTypeStr { get; set; } + } + public class Temp + { + public string Coupon_Range_Id { get; set; } + } + + public class CusomterCouponDTO + { + /// + /// wx号 + /// + public string OpenId { get; set; } + /// + /// 客户Id + /// + public string CustomerId { get; set; } + /// + /// 订单Id + /// + public string OrderId { get; set; } + /// + /// 优惠券名称 + /// + public string CouponTitle { get; set; } + /// + /// 优惠券Id + /// + public string CouponId { get; set; } + /// + /// 状态(1:未使用 2.已核销 3.占用中 4.失效) + /// + public int Stutas { get; set; } + /// + /// 状态汉字描述 + /// + public string StutasDes + { + get + { + if (Stutas == 1) + return "未使用"; + else if (Stutas == 2) + return "已核销"; + else if (Stutas == 3) + return "占用中"; + else + return "已失效"; + } + } + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/CustomerCouponPageDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/CustomerCouponPageDto.cs new file mode 100644 index 0000000..2ec82cc --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/CustomerCouponPageDto.cs @@ -0,0 +1,89 @@ +using BPA.KitChen.StoreManagement.Application.BaseDto; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.CouponServices.Dtos +{ + public class CustomerCouponPageDto : PageInputBase + { + /// + /// 客户Id + /// + public string CustomerId { get; set; } + /// + /// 状态(1:未使用 2.已核销 3.占用中 4.失效) 不传就是全部 + /// + public int? State { get; set; } + /// + /// 手机号 + /// + public string CustomerPhone { get; set; } + /// + /// 可用商品 + /// + public List GoodsId { get; set; } + /// + /// 总价 + /// + public decimal? TotalPrice { get; set; } + } + + public class CustomerCouponCanUseDto { + /// + /// 可用商品 + /// + [Required] + public List GoodsId { get; set; } + /// + /// 总价 + /// + public decimal? TotalPrice { get; set; } + /// + /// 客户Id + /// + [Required] + public string CustomerId { get; set; } + /// + /// 店铺Id + /// + [Required] + public List StoreId { get; set; } + } + + + public class CustomerCouponPageExDto : CustomerCouponPageDto + { + /// + /// 优惠券名称 + /// + public string CouponTitle { get; set; } + /// + /// 领取方式(1.小程序领取 2.线下门店扫码 3.活动自动下发 4.好友分享领取 5.指定发放) + /// + public int? ReceiveType { get; set; } + /// + /// 批次号 + /// + public string BatchNo { get; set; } + + public string StoreName { get; set; } + + public string OrderId { get; set; } + + /// + /// 创建时间 + /// + public DateTime? CreateAt { get; set; } + /// + /// 核销时间 + /// + public DateTime? WriteOffTime { get; set; } + /// + /// 客户手机号 + /// + public string CustomerPhone { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/CustomerCouponPageResultOutputDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/CustomerCouponPageResultOutputDto.cs new file mode 100644 index 0000000..e40f1e3 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/CustomerCouponPageResultOutputDto.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.CouponServices.Dtos +{ + public class CustomerCouponPageResultOutputDto + { + public string? Id { get; set; } + /// + /// 客户Id + /// + public string? CustomerId { get; set; } + /// + /// 订单Id + /// + public string? OrderId { get; set; } + /// + /// 领取方式(1.小程序领取 2.线下门店扫码 3.活动自动下发 4.好友分享领取 5.指定发放) + /// + public int? ReceiveType { get; set; } + /// + /// 状态(1:未使用 2.已核销 3.占用中 4.失效) + /// + public int? State { get; set; } + /// + /// 优惠券名称 + /// + public string? CouponTitle { get; set; } + /// + /// 适用范围类型 1.店铺 2.供应商 3.区域 + /// + public int? RangeType { get; set; } + /// + /// 结束时间 + /// + public DateTime? ValidEndTime { get; set; } + /// + /// 开始时间 + /// + public DateTime? ValidStartTime { get; set; } + /// + /// 核销时间 + /// + public DateTime? WriteOffTime { get; set; } + /// + /// 创建时间 + /// + public DateTime? CreateAt { get; set; } + /// + /// 店铺名称 + /// + public string? StoreName { get; set; } + /// + /// 客户手机号 + /// + public string? Phone { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/PageCouponInputDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/PageCouponInputDto.cs new file mode 100644 index 0000000..6844076 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/PageCouponInputDto.cs @@ -0,0 +1,69 @@ +using BPA.KitChen.StoreManagement.Application.BaseDto; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.CouponServices.Dtos +{ + + /// + /// + /// + public class PageCouponInputDto : PageInputBase + { + + /// + /// 优惠卷名称 + /// + public string CouponTitle { get; set; } + + /// + /// 优惠卷类型 + /// + public int CouponType { get; set; } + + /// + /// 优惠卷金额 + /// + public decimal CouponValue { get; set; } + + /// + ///使用金额 + /// + public decimal Condition { get; set; } + + /// + /// 时间类型 + /// + public int TimeType { get; set; } + + public int GetLimit { get; set; } + + + /// + /// 固定期限 + /// + public int ValidFixedTerm { get; set; } + + public DateTime? ValidStartTime { get; set; } + + public DateTime? ValidEndTime { get; set; } + + public DateTime? CreateAt { get; set; } + + + /// + /// 状态 + /// + + public int ValidStatus { get; set; } + + /// + /// 备注 + /// + public decimal Remarks { get; set; } + + + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/RebackDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/RebackDto.cs new file mode 100644 index 0000000..d58bb0f --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/RebackDto.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.CouponServices.Dtos +{ + public class RebackDto + { + public string Id { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/StatusOrTypeOutDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/StatusOrTypeOutDto.cs new file mode 100644 index 0000000..a9afb35 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/StatusOrTypeOutDto.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.CouponServices.Dtos +{ + public class StatusOrTypeOutDto + { + public int Key { get; set; } + + public string Value { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/UpdateStateDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/UpdateStateDto.cs new file mode 100644 index 0000000..5cd2f98 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/UpdateStateDto.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.CouponServices.Dtos +{ + public class UpdateStateDto + { + public string OdrerId { get; set; } + public int State { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/member/Class1.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/member/Class1.cs new file mode 100644 index 0000000..6d8ea3b --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/member/Class1.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.CouponServices.Dtos.member +{ + internal class Class1 + { + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/member/CustomerInfoInputDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/member/CustomerInfoInputDto.cs new file mode 100644 index 0000000..84d2c10 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/member/CustomerInfoInputDto.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.CouponServices.Dtos.member +{ + public class CustomerInfoInputDto + { + public int CurrentPage { get; set; } + public int PageSize { get; set; } + public string Phone { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/member/CustomerInfoOutputDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/member/CustomerInfoOutputDto.cs new file mode 100644 index 0000000..de5eed6 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/Dtos/member/CustomerInfoOutputDto.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.CouponServices.Dtos.member +{ + public class MemberInfoOutputDto + { + public string Phone { get; set; } + public string MemberId { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/ICouponServices.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/ICouponServices.cs new file mode 100644 index 0000000..88bd22b --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/CouponServices/ICouponServices.cs @@ -0,0 +1,194 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using BPA.KitChen.StoreManagement.Application.BaseDto; +using BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.CouponServices.Dtos.member; +using Microsoft.AspNetCore.Mvc; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.CouponServices.Dtos +{ + + /// + /// 优惠卷接口 + /// + public interface ICouponServices + { + + /// + ///获取优惠卷状态和类型 1.优惠卷状态 2.优惠卷类型 + /// + /// + /// + Task> GetCouponStatusOrTypeAsync(int type); + + /// + /// 新增优惠卷 + /// + Task AddCoupon(CouponBasetDto inputDto); + + /// + /// 获取优惠卷_分页 + /// + /// + /// + Task GetCouponPgageAsync(PageCouponInputDto inputDto); + + /// + /// 修改优惠卷 + /// + Task UpdateCoupon(CouponBasetDto inputDto); + + /// + /// 修改优惠券状态 + /// + /// + /// + Task UpdateCouponStatus( CouponBasetDto inputDto); + + /// + /// 删除优惠卷 + /// + Task DeleteCoupon(List Ids); + + /// + /// 作废 + /// + Task AbolishCoupon(string Id); + + /// + /// 领券支持批量领取 + /// + /// + /// + + Task ReceiveCoupon(List input); + /// + /// 指定客户领取 + /// + /// + /// + Task ReceiveCouponByInput(CustomerCouponInputDto input); + /// + /// 领券分页查看SAAS用 + /// + /// + /// + Task GetCustomerPage(CustomerCouponPageExDto input); + /// + /// 退单退券 + /// + /// + /// + Task RebackCoupon(string OrderId); + /// + /// 优惠券使用状态 + /// + /// + /// + Task CustomerCouponOff(CustomerCouponBaseDto input); + /// + /// 失效优惠卷 + /// + /// + /// + Task AbolishCustomerCoupon(string Id); + /// + /// 查看领取的优惠券 + /// + /// + /// + Task WacthCoupon(CustomerCouponPageDto input); + /// + /// 回调写入优惠券状态 + /// + /// + /// + /// + Task UpdateState(string OdrerId, int State); + /// + /// 查看优惠券流水 + /// + /// + /// + Task> GetCouponLog(string couponCustomerId); + /// + /// 根据订单号获取用户的优惠券使用状态 + /// + /// + /// + Task> GetCouponStutasByOrderId(List OrderId); + /// + /// 领券详情 + /// + /// + /// + Task CustomerCouponDetail(string Id); + /// + /// 新增发券记录 + /// + /// + /// + Task AddCouponSendRecord(CouponRecordDto input); + /// + /// 获取发券记录 + /// + /// + /// + Task GetCouponRecordById(CouponRecordPageDto input); + /// + /// 记录汇总 + /// + /// + /// + Task GetCouponRecordPage(CouponRecordPageDto input); + /// + /// 召回禁用优惠卷 + /// + /// + /// + Task RecallCoupon(CouponRecordDto input); + /// + /// 召回禁用优惠卷商品 + /// + /// + /// + Task RecallCouponGoods(CouponRecordDto input); + /// + /// 获取发券的管理记录商品 + /// + /// + /// + Task GetCouponRecordGoods(CouponRecordPageDto input); + /// + /// 查询可用券 + /// + /// + /// + Task> SelectCanUseCoupon(CustomerCouponCanUseDto input); + + + + /// + /// 获取商品类型 + /// + /// + Task> GetGoodsType(); + + /// + /// 获取商品 + /// + /// + /// + Task> GetGoods(string GoodsTypeId); + + /// + /// 获取会员信息 + /// + /// + /// + Task> GetCustomerInfo(CustomerInfoInputDto input); + + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/GoodsCoupon/Dtos/Class1.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/GoodsCoupon/Dtos/Class1.cs new file mode 100644 index 0000000..8b31c43 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/GoodsCoupon/Dtos/Class1.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.GoodsCoupon.Dtos +{ + internal class Class1 + { + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/GoodsCoupon/Dtos/GoodsCouponBasetDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/GoodsCoupon/Dtos/GoodsCouponBasetDto.cs new file mode 100644 index 0000000..59e948d --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/GoodsCoupon/Dtos/GoodsCouponBasetDto.cs @@ -0,0 +1,54 @@ +using Microsoft.AspNetCore.Components.Forms; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.GoodsCoupon.Dtos +{ + public class GoodsCouponBasetDto + { + public string Id { get; set; } + /// + /// 商品id + /// + public string GoodsId { get; set; } + /// + /// 店铺id + /// + public string StoreId { get; set; } + /// + /// 标题 + /// + public string Title { get; set; } + /// + /// 商品名称 + /// + public string GoodsName { get; set; } + /// + /// 类型(平台)id + /// + public string CTypeId { get; set; } + /// + /// 原始金额 + /// + public decimal? Money { get; set; } + /// + /// 平台金额 + /// + public decimal SoureMoney { get; set; } + /// + /// 加盟商id + /// + public string GroupId { get; set; } + /// + /// 创建时间 + /// + public DateTime CrateTimeAt { get; set; } + /// + /// 是否启用 + /// + public bool? Enable { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/GoodsCoupon/Dtos/GoodsCouponReportDatadto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/GoodsCoupon/Dtos/GoodsCouponReportDatadto.cs new file mode 100644 index 0000000..e884ce4 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/GoodsCoupon/Dtos/GoodsCouponReportDatadto.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.GoodsCoupon.Dtos +{ + public class GoodsCouponReportDatadto + { + public string Id { get; set; } + /// + /// 标题 + /// + public string Title { get; set; } + /// + /// 类型 + /// + public string CTypeId { get; set; } + /// + /// 商品名称 + /// + public string GoodsName { get; set; } + /// + /// 平台金额 + /// + public decimal SoureMoney { get; set; } + public string CTypeName { get; set; } + /// + /// 金额 + /// + public decimal? Money { get; set; } + /// + /// 创建时间 + /// + public DateTime CrateTimeAt { get; set; } + /// + /// 数量 + /// + public int Allcount { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/GoodsCoupon/Dtos/PageGoodsCouponInputDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/GoodsCoupon/Dtos/PageGoodsCouponInputDto.cs new file mode 100644 index 0000000..8110256 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/GoodsCoupon/Dtos/PageGoodsCouponInputDto.cs @@ -0,0 +1,39 @@ +using BPA.KitChen.StoreManagement.Application.BaseDto; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.GoodsCoupon.Dtos +{ + public class PageGoodsCouponInputDto:PageInputBase + { + /// + /// 优惠卷名称 + /// + public string Title { get; set; } + + /// + /// 优惠卷类型 + /// + public string CTypeId { get; set; } + + /// + /// 优惠卷金额 + /// + public decimal Money { get; set; } + /// + /// 店铺名称 + /// + public string GoodsName { get; set; } + /// + /// 店铺id + /// + public string StoreId { get; set; } + /// + /// 是否启用 + /// + public bool? Enable { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/GoodsCoupon/GoodsCouponServices.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/GoodsCoupon/GoodsCouponServices.cs new file mode 100644 index 0000000..e92e984 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/GoodsCoupon/GoodsCouponServices.cs @@ -0,0 +1,192 @@ +using Furion.FriendlyException; +using Furion; +using Microsoft.AspNetCore.Mvc; +using SqlSugar; +using Mapster; +using Furion.DependencyInjection; +using BPA.KitChen.StoreManagement.Application.BaseDto; +using BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.GoodsCoupon.Dtos; +using BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.PaperCouponsServices.Dtos; +using BPA.KitChen.StoreManagement.Core.Common; +using BPA.KitChen.StoreManagement.Core.Common.Const; +using BPA.KitChen.StoreManagement.Core.Entity.Coupon; +using BPA.KitChen.StoreManagement.SqlSugar; +using BPA.Models.BPA_Kitchen; +using BPA.KitChen.StoreManagement.Core.Entity; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.GoodsCoupon +{ + public class GoodsCouponServices : SupperRepository, IGoodsCouponServices, ITransient + { + + private readonly SqlSugarScope db; // 核心对象:拥有完整的SqlSugar全部功能 + + public GoodsCouponServices() + { + db = SqlSugarDb.Db; + + } + /// + /// / 获取优惠卷_分页 + /// + /// + /// + public async Task GetGoodsCouponPgageAsync(PageGoodsCouponInputDto inputDto) + { + var groupId = string.IsNullOrWhiteSpace(CurrentUser.TenantId) + ? App.User?.FindFirst(ClaimConst.GroupId)?.Value + : CurrentUser.TenantId; + if (string.IsNullOrWhiteSpace(groupId)) throw Oops.Oh("加盟商不能为空"); + var result = new List(); + var total = new RefAsync(); + var queryable = await db.Queryable((a, b,c) => + new JoinQueryInfos( + JoinType.Left, a.CTypeId == b.Id, + JoinType.Left, a.StoreId == c.Id)) + .Where((a, b,c) => a.GroupId == groupId) + .WhereIF(!string.IsNullOrWhiteSpace(inputDto.CTypeId), a => a.CTypeId == inputDto.CTypeId) + .WhereIF(!string.IsNullOrWhiteSpace(inputDto.Title), a => a.Title.Contains(inputDto.Title)) + .WhereIF(!string.IsNullOrWhiteSpace(inputDto.GoodsName), a => a.GoodsName.Contains(inputDto.GoodsName)) + .WhereIF(inputDto.Money > 0, a => a.Money == inputDto.Money) + .WhereIF(!string.IsNullOrWhiteSpace(inputDto.StoreId),a=>a.StoreId== inputDto.StoreId) + .WhereIF(inputDto.Enable != null, a => a.Enable == inputDto.Enable) + .Select((a, b,c) => new PaperCouponBasetDto() + { + Id = a.Id, + CTypeId = a.CTypeId, + Title = a.Title, + SoureMoney=a.SoureMoney, + GoodsId= a.GoodsId, + StoreId= a.StoreId, + StoreName=c.Name, + Money = a.Money, + GoodsName=a.GoodsName, + CTypeName = b.Name, + CrateTimeAt = a.CrateTimeAt, + Enable=a.Enable, + }).ToPagedListAsync(inputDto.Current, inputDto.PageSize); + result = queryable.Items.ToList(); + return new PageUtil + { + Total = queryable.TotalCount, + Data = result + }; + } + + /// + /// 新增优惠卷 + /// + /// + /// + public async Task AddGoodsCoupon(GoodsCouponBasetDto inputDto) + { + if (string.IsNullOrWhiteSpace(inputDto.GoodsId)) + { + throw Oops.Oh("商品不能为空"); + } + if (string.IsNullOrWhiteSpace(inputDto.Title)) + { + throw Oops.Oh("标题参数不能为空"); + } + if (string.IsNullOrWhiteSpace(inputDto.CTypeId)) + { + throw Oops.Oh("平台参数不能为空"); + } + if (inputDto.Money == null) + { + throw Oops.Oh("原始金额参数不能为空"); + } + if (inputDto.SoureMoney == null) + { + throw Oops.Oh("平台金额参数不能为空"); + } + var checkMoneyType = db.Queryable().Any(x => x.CTypeId == inputDto.CTypeId && x.SoureMoney== inputDto.SoureMoney && x.Money == inputDto.Money && x.GoodsId == inputDto.GoodsId && x.StoreId== inputDto.StoreId); + if (checkMoneyType) throw Oops.Oh("已存在相同平台金额的商品优惠卷"); + inputDto.Id= Guid.NewGuid().ToString(); + inputDto.CrateTimeAt = DateTime.Now; + inputDto.Enable = true; + var result = await db.Insertable(inputDto.Adapt()).ExecuteCommandAsync(); + + return await Task.FromResult(result > 0); + } + + /// + /// 更新优惠卷启用状态 + /// + /// + /// + public async Task UpdateGoodsCouponEnable(string Ids) + { + var model = db.Queryable().First(x => Ids.Contains(x.Id)); + if (model == null) throw Oops.Oh("数据不存在"); + model.Enable = !model.Enable; + var result = db.Updateable(model).ExecuteCommand(); + return result > 0; + } + + /// + /// 修改优惠卷 + /// + /// + /// + public async Task UpdateGoodsCoupon([FromBody] GoodsCouponBasetDto inputDto) + { + if (string.IsNullOrWhiteSpace(inputDto.Title)) + { + throw Oops.Oh("标题参数不能为空"); + } + if (string.IsNullOrWhiteSpace(inputDto.CTypeId)) + { + throw Oops.Oh("类型参数不能为空"); + } + if (inputDto.Money == null) + { + throw Oops.Oh("金额参数不能为空"); + } + if (inputDto.Money < 0) + { + throw Oops.Oh("金额不能小于0"); + } + var result = db.Updateable(inputDto.Adapt()).UpdateColumns(it => + new { it.Title, it.Money, it.CTypeId,it.GoodsId,it.GoodsName,it.SoureMoney }).ExecuteCommand(); + return await Task.FromResult(result > 0); + } + /// + /// 统计报表F + /// + /// + /// + public async Task> GetGoodsCouponReport(PaperCouponReportdto paperCouponReportdto) + { + var groupId = string.IsNullOrWhiteSpace(CurrentUser.TenantId) + ? App.User?.FindFirst(ClaimConst.GroupId)?.Value + : CurrentUser.TenantId; + if (string.IsNullOrWhiteSpace(groupId)) throw Oops.Oh("加盟商不能为空"); + var queryable = await db.Queryable((a, b) => a.CTypeId == b.Id) + .Where((a,b)=>a.GroupId== groupId) + .WhereIF(!string.IsNullOrWhiteSpace(paperCouponReportdto.CTypeId), a => a.CTypeId == paperCouponReportdto.CTypeId) + .WhereIF(paperCouponReportdto.Money > 0, a => a.Money == paperCouponReportdto.Money) + + .Select((a, b) => new GoodsCouponReportDatadto() + { + Id = a.Id, + CTypeId = a.CTypeId, + Title = a.Title, + Money = a.Money, + SoureMoney= a.SoureMoney, + GoodsName= a.GoodsName, + CTypeName = b.Name, + CrateTimeAt = a.CrateTimeAt + }).Mapper(p => + { + p.Allcount = db.Queryable() + .Where(x => x.GoodsCouponId == p.Id && x.GroupId == groupId) + .WhereIF(!string.IsNullOrWhiteSpace(paperCouponReportdto.StartDateStr), c => c.CreateAt >= Convert.ToDateTime(paperCouponReportdto.StartDateStr)) + .WhereIF(!string.IsNullOrWhiteSpace(paperCouponReportdto.EndDateStr), c => c.CreateAt <= Convert.ToDateTime(paperCouponReportdto.EndDateStr)) + .Count(); + }) + .ToListAsync(); + return queryable; + } + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/GoodsCoupon/IGoodsCouponServices.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/GoodsCoupon/IGoodsCouponServices.cs new file mode 100644 index 0000000..b67ab8b --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/GoodsCoupon/IGoodsCouponServices.cs @@ -0,0 +1,49 @@ +using BPA.KitChen.StoreManagement.Application.BaseDto; +using BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.GoodsCoupon.Dtos; +using BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.PaperCouponsServices.Dtos; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.GoodsCoupon +{ + /// + /// 接口服务 + /// + public interface IGoodsCouponServices + { + /// + /// 获取优惠卷_分页 + /// + /// + /// + Task GetGoodsCouponPgageAsync(PageGoodsCouponInputDto inputDto); + /// + /// 新增优惠卷 + /// + /// + /// + Task AddGoodsCoupon(GoodsCouponBasetDto inputDto); + /// + /// 更新优惠卷启用状态 + /// + /// + /// + Task UpdateGoodsCouponEnable(string Ids); + /// + /// 修改优惠卷 + /// + /// + /// + Task UpdateGoodsCoupon([FromBody] GoodsCouponBasetDto inputDto); + /// + /// 统计报表 + /// + /// + /// + Task> GetGoodsCouponReport(PaperCouponReportdto paperCouponReportdto); + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/GoodsCouponService.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/GoodsCouponService.cs new file mode 100644 index 0000000..17191ac --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/GoodsCouponService.cs @@ -0,0 +1,86 @@ +using BPA.KitChen.StoreManagement.Application.BaseDto; +using BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.GoodsCoupon; +using BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.GoodsCoupon.Dtos; +using BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.PaperCouponsServices.Dtos; +using Furion.DependencyInjection; +using Furion.DynamicApiController; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon +{ + /// + /// 商品优惠卷管理 + /// + [ApiDescriptionSettings("商品优惠券", Tag = "商品优惠卷管理")] + public class GoodsCouponService : IDynamicApiController, ITransient + { + IGoodsCouponServices _goodsCouponServices; + /// + /// + /// + /// + public GoodsCouponService(IGoodsCouponServices goodsCouponServices) + { + _goodsCouponServices=goodsCouponServices; + } + /// + /// 获取优惠卷_分页 + /// + /// + /// + [HttpPost("/api/goodscoupon/getGoodsCouponPgage")] + [AllowAnonymous] + public async Task GetGoodsCouponPgage([FromBody] PageGoodsCouponInputDto inputDto) + { + return await _goodsCouponServices.GetGoodsCouponPgageAsync(inputDto); + } + /// + /// 新增优惠卷 + /// + /// + /// + [HttpPost("/api/goodscoupon/addGoodsCoupon")] + public async Task AddGoodsCoupon(GoodsCouponBasetDto inputDto) + { + return await _goodsCouponServices.AddGoodsCoupon(inputDto); + } + + /// + /// 更新优惠卷启用状态 + /// + /// + /// + [HttpGet("/api/goodscoupon/updateGoodsCouponEnable")] + public async Task UpdateGoodsCouponEnable(string Ids) + { + return await _goodsCouponServices.UpdateGoodsCouponEnable(Ids); + } + /// + /// 修改优惠卷 + /// + /// + /// + [HttpPost("/api/goodscoupon/updateGoodsCoupon")] + public async Task UpdateGoodsCoupon(GoodsCouponBasetDto inputDto) + { + return await _goodsCouponServices.UpdateGoodsCoupon(inputDto); + } + /// + /// 优惠卷报表统计 + /// + /// + /// + [HttpPost("/api/goodscoupon/getGoodsCouponReport")] + [AllowAnonymous] + public async Task> GetPaperCouponReport(PaperCouponReportdto inputDto) + { + return await _goodsCouponServices.GetGoodsCouponReport(inputDto); + } + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/PaperCouponsService.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/PaperCouponsService.cs new file mode 100644 index 0000000..1919523 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/PaperCouponsService.cs @@ -0,0 +1,103 @@ +using BPA.KitChen.StoreManagement.Application.BaseDto; +using BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.PaperCouponsServices; +using BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.PaperCouponsServices.Dtos; +using Furion.DependencyInjection; +using Furion.DynamicApiController; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.Kitchen.CRM.CouponCenter +{ + [ApiDescriptionSettings("纸质优惠券", Tag = "纸质优惠券管理")] + public class PaperCouponsService: IDynamicApiController, ITransient + { + readonly IPaperCouponsServices _paperCouponsServices; + /// + /// + /// + /// + public PaperCouponsService(IPaperCouponsServices paperCouponsServices) + { + _paperCouponsServices = paperCouponsServices; + + } + /// + /// 获取优惠卷_分页 + /// + /// + /// + [HttpPost("/api/papercoupon/paperCouponPgage")] + [AllowAnonymous] + public async Task PaperCouponPgage([FromBody] PagePaperCouponInputDto inputDto) + { + return await _paperCouponsServices.GetPaperCouponPgageAsync(inputDto); + } + /// + /// 新增优惠卷 + /// + /// + /// + [HttpPost("/api/papercoupon/addPaperCoupon")] + public async Task AddPaperCoupon(PaperCouponBasetDto inputDto) + { + return await _paperCouponsServices.AddPaperCoupon(inputDto); + } + + /// + /// 删除优惠卷 + /// + /// + /// + [HttpGet("/api/papercoupon/updatePaperCouponEnable")] + public async Task UpdatePaperCouponEnable(string Ids) + { + return await _paperCouponsServices.UpdatePaperCouponEnable(Ids); + } + /// + /// 修改优惠卷 + /// + /// + /// + [HttpPost("/api/papercoupon/updatePaperCoupon")] + public async Task UpdateCoupon(PaperCouponBasetDto inputDto) + { + return await _paperCouponsServices.UpdatePaperCoupon(inputDto); + } + /// + /// 新增优惠卷类型 + /// + /// + /// + [HttpPost("/api/papercoupon/addPaperCouponType")] + public async Task AddPaperCouponType(PaperCouponTypeBasetDto inputDto) + { + return await _paperCouponsServices.AddPaperCouponType(inputDto); + } + /// + /// 查询所有优惠卷类型 + /// + /// + [HttpGet("/api/papercoupon/getPaperCouponType")] + [AllowAnonymous] + public async Task> GetPaperCouponType() + { + return await _paperCouponsServices.GetPaperCouponType(); + } + /// + /// 优惠卷报表统计 + /// + /// + /// + [HttpPost("/api/papercoupon/getPaperCouponReport")] + [AllowAnonymous] + public async Task> GetPaperCouponReport(PaperCouponReportdto inputDto) + { + return await _paperCouponsServices.GetPaperCouponReport(inputDto); + } + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/PaperCouponsServices/Dtos/PagePaperCouponInputDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/PaperCouponsServices/Dtos/PagePaperCouponInputDto.cs new file mode 100644 index 0000000..f69e6ed --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/PaperCouponsServices/Dtos/PagePaperCouponInputDto.cs @@ -0,0 +1,31 @@ +using BPA.KitChen.StoreManagement.Application.BaseDto; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.PaperCouponsServices.Dtos +{ + public class PagePaperCouponInputDto: PageInputBase + { + /// + /// 优惠卷名称 + /// + public string Title { get; set; } + + /// + /// 优惠卷类型 + /// + public string CTypeId { get; set; } + + /// + /// 优惠卷金额 + /// + public decimal Money { get; set; } + /// + /// 是否启用 + /// + public bool? Enable { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/PaperCouponsServices/Dtos/PaperCouponBasetDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/PaperCouponsServices/Dtos/PaperCouponBasetDto.cs new file mode 100644 index 0000000..4484360 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/PaperCouponsServices/Dtos/PaperCouponBasetDto.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.PaperCouponsServices.Dtos +{ + public class PaperCouponBasetDto + { + public string Id { get; set; } + public string GoodsId { get; set; } + /// + /// 商品名称 + /// + public string GoodsName { get; set; } + /// + /// 店铺id + /// + public string StoreId { get; set; } + /// + /// 店铺 + /// + public string StoreName { get; set; } + /// + /// 标题 + /// + public string Title { get; set; } + /// + /// 类型 + /// + public string CTypeId { get; set; } + public string CTypeName { get; set; } + /// + /// 金额 + /// + public decimal? Money { get; set; } + /// + /// 平台金额 + /// + public decimal SoureMoney { get; set; } + /// + /// 创建时间 + /// + public DateTime CrateTimeAt { get; set; } + public bool? Enable { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/PaperCouponsServices/Dtos/PaperCouponReportDatadto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/PaperCouponsServices/Dtos/PaperCouponReportDatadto.cs new file mode 100644 index 0000000..36766f1 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/PaperCouponsServices/Dtos/PaperCouponReportDatadto.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.PaperCouponsServices.Dtos +{ + public class PaperCouponReportDatadto + { + public string Id { get; set; } + /// + /// 标题 + /// + public string Title { get; set; } + /// + /// 类型 + /// + public string CTypeId { get; set; } + public string CTypeName { get; set; } + /// + /// 金额 + /// + public decimal? Money { get; set; } + /// + /// 平台金额 + /// + public decimal? SoureMoney { get; set; } + /// + /// 创建时间 + /// + public DateTime CrateTimeAt { get; set; } + /// + /// 数量 + /// + public int Allcount { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/PaperCouponsServices/Dtos/PaperCouponReportdto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/PaperCouponsServices/Dtos/PaperCouponReportdto.cs new file mode 100644 index 0000000..b1d3e1d --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/PaperCouponsServices/Dtos/PaperCouponReportdto.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.PaperCouponsServices.Dtos +{ + public class PaperCouponReportdto + { + public string StartDateStr { get; set; } + public string EndDateStr { get; set; } + public string CTypeId { get; set; } + public decimal Money { get; set; } + + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/PaperCouponsServices/Dtos/PaperCouponTypeBasetDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/PaperCouponsServices/Dtos/PaperCouponTypeBasetDto.cs new file mode 100644 index 0000000..89e875c --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/PaperCouponsServices/Dtos/PaperCouponTypeBasetDto.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.PaperCouponsServices.Dtos +{ + public class PaperCouponTypeBasetDto + { + public string Id { get; set; } + /// + /// 类型名称 + /// + public string Name { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/PaperCouponsServices/Dtos/PaperCouponTypeSelectDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/PaperCouponsServices/Dtos/PaperCouponTypeSelectDto.cs new file mode 100644 index 0000000..3af601f --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/PaperCouponsServices/Dtos/PaperCouponTypeSelectDto.cs @@ -0,0 +1,15 @@ +using Microsoft.AspNetCore.Http; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.PaperCouponsServices.Dtos +{ + public class PaperCouponTypeSelectDto + { + public string Key { get; set; } + public string Value { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/PaperCouponsServices/IPaperCouponsServices.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/PaperCouponsServices/IPaperCouponsServices.cs new file mode 100644 index 0000000..7386bb1 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/PaperCouponsServices/IPaperCouponsServices.cs @@ -0,0 +1,57 @@ + +using BPA.KitChen.StoreManagement.Application.BaseDto; +using BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.PaperCouponsServices.Dtos; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.PaperCouponsServices +{ + public interface IPaperCouponsServices + { + /// + /// 分页查询数据 + /// + /// + /// + Task GetPaperCouponPgageAsync(PagePaperCouponInputDto inputDto); + /// + /// 添加数据 + /// + /// + /// + Task AddPaperCoupon(PaperCouponBasetDto inputDto); + /// + /// 删除数据 + /// + /// + /// + Task UpdatePaperCouponEnable(string Ids); + /// + /// 更新数据 + /// + /// + /// + Task UpdatePaperCoupon([FromBody] PaperCouponBasetDto inputDto); + /// + /// 添加优惠卷类型 + /// + /// + /// + Task AddPaperCouponType(PaperCouponTypeBasetDto inputDto); + /// + /// 查询所有优惠卷类型 + /// + /// + Task> GetPaperCouponType(); + /// + /// 统计 + /// + /// + /// + Task> GetPaperCouponReport(PaperCouponReportdto paperCouponReportdto); + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/PaperCouponsServices/PaperCouponsServices.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/PaperCouponsServices/PaperCouponsServices.cs new file mode 100644 index 0000000..d7e8ec6 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Coupon/PaperCouponsServices/PaperCouponsServices.cs @@ -0,0 +1,193 @@ +using BPA.KitChen.StoreManagement.Application.BaseDto; +using BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.PaperCouponsServices.Dtos; +using BPA.KitChen.StoreManagement.Core.Common; +using BPA.KitChen.StoreManagement.Core.Common.Const; +using BPA.KitChen.StoreManagement.Core.Entity.Coupon; +using BPA.KitChen.StoreManagement.SqlSugar; +using Furion; +using Furion.DependencyInjection; +using Furion.FriendlyException; +using Mapster; +using Microsoft.AspNetCore.Mvc; +using SqlSugar; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Coupon.PaperCouponsServices +{ + /// + /// 纸质优惠卷服务 + /// + public class PaperCouponsServices: SupperRepository, IPaperCouponsServices, ITransient + { + private readonly SqlSugarScope db; // 核心对象:拥有完整的SqlSugar全部功能 + + public PaperCouponsServices() + { + db = SqlSugarDb.Db; + + } + /// + /// / 获取优惠卷_分页 + /// + /// + /// + public async Task GetPaperCouponPgageAsync(PagePaperCouponInputDto inputDto) + { + var groupId = string.IsNullOrWhiteSpace(CurrentUser.TenantId) + ? App.User?.FindFirst(ClaimConst.GroupId)?.Value + : CurrentUser.TenantId; + if (string.IsNullOrWhiteSpace(groupId)) throw Oops.Oh("加盟商不能为空"); + var result = new List(); + var total = new RefAsync(); + var queryable =await db.Queryable((a, b) => a.CTypeId == b.Id) + .Where((a,b)=>a.GroupId== groupId) + .WhereIF(!string.IsNullOrWhiteSpace(inputDto.CTypeId), a => a.CTypeId == inputDto.CTypeId) + .WhereIF(!string.IsNullOrWhiteSpace(inputDto.Title), a => a.Title.Contains(inputDto.Title)) + .WhereIF(inputDto.Money > 0, a => a.Money == inputDto.Money) + .WhereIF(inputDto.Enable!=null,a=>a.Enable== inputDto.Enable) + .Select((a,b)=>new PaperCouponBasetDto() + { + Id=a.Id, CTypeId=a.CTypeId, Title=a.Title,Money=a.Money,CTypeName=b.Name,CrateTimeAt=a.CrateTimeAt,Enable=a.Enable,SoureMoney=a.SoureMoney + }).ToPagedListAsync(inputDto.Current, inputDto.PageSize); + result = queryable.Items.ToList(); + return new PageUtil + { + Total = queryable.TotalCount, + Data = result + }; + } + + /// + /// 新增优惠卷 + /// + /// + /// + public async Task AddPaperCoupon(PaperCouponBasetDto inputDto) + { + if (string.IsNullOrWhiteSpace(inputDto.Title)) + { + throw Oops.Oh("标题参数不能为空"); + } + if (string.IsNullOrWhiteSpace(inputDto.CTypeId)) + { + throw Oops.Oh("类型参数不能为空"); + } + if (inputDto.Money==null) + { + throw Oops.Oh("金额参数不能为空"); + } + var checkMoneyType=db.Queryable().Any(x => x.CTypeId == inputDto.CTypeId && x.Money == inputDto.Money); + if(checkMoneyType) throw Oops.Oh("已存在相同类型金额的优惠卷"); + inputDto.Id = Guid.NewGuid().ToString(); + inputDto.CrateTimeAt = DateTime.Now; + inputDto.Enable= true; + var result = await db.Insertable(inputDto.Adapt()).ExecuteCommandAsync(); + + return await Task.FromResult(result > 0); + } + + /// + /// 删除优惠卷 + /// + /// + /// + public async Task UpdatePaperCouponEnable(string Ids) + { + var model = db.Queryable().First(x => Ids.Contains(x.Id)); + if (model == null) throw Oops.Oh("数据不存在"); + model.Enable = !model.Enable; + var result = db.Updateable(model).ExecuteCommand(); + return result > 0; + } + + /// + /// 修改优惠卷 + /// + /// + /// + public async Task UpdatePaperCoupon([FromBody] PaperCouponBasetDto inputDto) + { + if (string.IsNullOrWhiteSpace(inputDto.Title)) + { + throw Oops.Oh("标题参数不能为空"); + } + if (string.IsNullOrWhiteSpace(inputDto.CTypeId)) + { + throw Oops.Oh("类型参数不能为空"); + } + if (inputDto.Money == null) + { + throw Oops.Oh("金额参数不能为空"); + } + if (inputDto.Money<0) + { + throw Oops.Oh("金额不能小于0"); + } + if (inputDto.SoureMoney < 0) + { + throw Oops.Oh("金额不能小于0"); + } + var result = db.Updateable(inputDto.Adapt()).UpdateColumns(it => + new { it.Title,it.Money,it.CTypeId }).ExecuteCommand(); + return await Task.FromResult(result > 0); + } + /// + /// 新增优惠卷 + /// + /// + /// + public async Task AddPaperCouponType(PaperCouponTypeBasetDto inputDto) + { + if (string.IsNullOrWhiteSpace(inputDto.Name)) + { + throw Oops.Oh("标题参数不能为空"); + } + var checkMoneyType = db.Queryable().Any(x => x.Name == inputDto.Name); + if (checkMoneyType) throw Oops.Oh("已存在相同名称的类型"); + inputDto.Id = Guid.NewGuid().ToString(); + var result = await db.Insertable(inputDto.Adapt()).ExecuteCommandAsync(); + + return await Task.FromResult(result > 0); + } + /// + /// 查询所有优惠卷类型 + /// + /// + public async Task> GetPaperCouponType() + { + var list= await db.Queryable().Select(x=>new PaperCouponTypeSelectDto() + { + Key=x.Id,Value=x.Name + }).ToListAsync(); + return list; + } + public async Task> GetPaperCouponReport(PaperCouponReportdto paperCouponReportdto) + { + var groupId = string.IsNullOrWhiteSpace(CurrentUser.TenantId) + ? App.User?.FindFirst(ClaimConst.GroupId)?.Value + : CurrentUser.TenantId; + var queryable = await db.Queryable((a, b) => a.CTypeId == b.Id) + .WhereIF(!string.IsNullOrWhiteSpace(paperCouponReportdto.CTypeId), a => a.CTypeId == paperCouponReportdto.CTypeId) + .WhereIF(paperCouponReportdto.Money > 0, a => a.Money == paperCouponReportdto.Money) + + .Select((a, b) => new PaperCouponReportDatadto() + { + Id = a.Id, + CTypeId = a.CTypeId, + Title = a.Title, + Money = a.Money, + SoureMoney= a.SoureMoney, + CTypeName = b.Name, + CrateTimeAt = a.CrateTimeAt + }).Mapper(p => + { + p.Allcount= db.Queryable() + .Where(x => x.PaperCouponId == p.Id && x.GroupId== groupId) + .WhereIF(!string.IsNullOrWhiteSpace(paperCouponReportdto.StartDateStr),c=>c.CreateAt>=Convert.ToDateTime(paperCouponReportdto.StartDateStr)) + .WhereIF(!string.IsNullOrWhiteSpace(paperCouponReportdto.EndDateStr), c => c.CreateAt <=Convert.ToDateTime(paperCouponReportdto.EndDateStr)) + .Count(); + }) + .ToListAsync(); + return queryable; + } + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/FoodMenu/IFoodMenuServices.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/FoodMenu/IFoodMenuServices.cs index 43b368c..6391222 100644 --- a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/FoodMenu/IFoodMenuServices.cs +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/FoodMenu/IFoodMenuServices.cs @@ -1,4 +1,7 @@ -using System; +using BPA.KitChen.StoreManagement.Application.BaseDto; +using BPA.KitChen.StoreManagement.Application.Service.ShopManage.FoodMenu.Dtos; +using Microsoft.AspNetCore.Mvc; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -8,5 +11,13 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.FoodMenu { public interface IFoodMenuServices { + + /// + /// 获取菜品列表 + /// + /// + /// + [HttpPost("/api/FoodMenu/GetGoodsByMenuIdPage")] + Task GetGoodsByMenuIdPage(FoodMenuQueryInputDto inputDto); } } diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberInfo/Dtos/Class1.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberInfo/Dtos/Class1.cs new file mode 100644 index 0000000..5f4e9f4 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberInfo/Dtos/Class1.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Member.MemberInfo.Dtos +{ + internal class Class1 + { + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberInfo/Dtos/CreateOrUpdateMemberInfoInputDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberInfo/Dtos/CreateOrUpdateMemberInfoInputDto.cs new file mode 100644 index 0000000..d2109c2 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberInfo/Dtos/CreateOrUpdateMemberInfoInputDto.cs @@ -0,0 +1,85 @@ +using BPA.KitChen.StoreManagement.Application.BaseDto; +using BPA.KitChen.StoreManagement.Core.Enum; +using Furion.DataValidation; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.OneCard.StoredValueCard.Dto +{ + public class CreateOrUpdateMemberInfoInputDto + { + public string MemberInfo_Id { get; set; } + + /// + /// + /// + public string NickName { get; set; } + /// + /// 0=未知 1=男 2=女 + /// + [Range(0, 2, ErrorMessage = "性别错误")] + public int Sex { get; set; } + /// + /// 头像 + /// + public string HeadImgUrl { get; set; } + /// + /// 国家 + /// + public string Country { get; set; } + /// + /// 省 + /// + public string Province { get; set; } + /// + /// 市 + /// + public string City { get; set; } + /// + /// 县(区) + /// + public string County { get; set; } + /// + /// 具体地址 + /// + public string Address { get; set; } + /// + /// 出生日期 + /// + public DateTime Birthday { get; set; } + /// + /// 电话 + /// + [RegularExpression("^1[3|4|5|7|8][0-9]{9}$")] + public string Phone { get; set; } + /// + /// 真实姓名 + /// + public string RealName { get; set; } + /// + /// 身份证号码 + /// + + [RegularExpression("^(\\d{15}$|^\\d{18}$|^\\d{17}(\\d|X|x))$")] + public string CardNum { get; set; } + /// + /// 等级 + /// + public string Level_Id { get; set; } + /// + /// 向外展示那个平台的信息 0:默认 1.微信 2.支付宝 3.POS 4.卡会员 + /// + [CustomValidation(typeof(DtoValidator), "MemberPlatformType")] + public PlatformType ShowPlatformType { get; set; } + + public int PlatformType { get; set; } + + [CustomValidation(typeof(DtoValidator), "Status")] + public CommonStatus Status { get; set; } + + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberInfo/Dtos/GetMemberInfoQueryInputDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberInfo/Dtos/GetMemberInfoQueryInputDto.cs new file mode 100644 index 0000000..8951930 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberInfo/Dtos/GetMemberInfoQueryInputDto.cs @@ -0,0 +1,29 @@ +using BPA.KitChen.StoreManagement.Application.BaseDto; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Member.MemberInfo.Dtos +{ + public class GetMemberInfoQueryInputDto : PageInputBase + { + /// + /// 昵称 + /// + public string NickName { get; set; } + /// + /// 真实姓名 + /// + public string RealName { get; set; } + /// + /// 电话 + /// + public string Phone { get; set; } + /// + /// Status + /// + public string Status { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberInfo/Dtos/MemberAccountPageInputDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberInfo/Dtos/MemberAccountPageInputDto.cs new file mode 100644 index 0000000..4f08275 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberInfo/Dtos/MemberAccountPageInputDto.cs @@ -0,0 +1,12 @@ +using BPA.KitChen.StoreManagement.Application.BaseDto; + +namespace BPA.KitChen.StoreManagement.Application.Service.OneCard.StoredValueCard.Dto +{ + public class MemberAccountPageInputDto: PageInputBase + { + public string MemberInfoId { get; set; } + public string Name { get; set; } + + public string CardNum { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberInfo/Dtos/MemberInfoBaseDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberInfo/Dtos/MemberInfoBaseDto.cs new file mode 100644 index 0000000..7e7d635 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberInfo/Dtos/MemberInfoBaseDto.cs @@ -0,0 +1,121 @@ +using BPA.Kitchen.Core.Common; +using BPA.KitChen.StoreManagement.Application.Service.OneCard.StoredValueCard.Dto; +using BPA.KitChen.StoreManagement.Core.Enum; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Member.MemberInfo.Dtos +{ + public class MemberInfoBaseDto + { + /// + /// + /// + public string Id { get; set; } + /// + /// + /// + public string NickName { get; set; } + /// + /// 0=未知 1=男 2=女 + /// + public int Sex { get; set; } + /// + /// 头像 + /// + public string HeadImgUrl { get; set; } + /// + /// 国家 + /// + public string Country { get; set; } + /// + /// 省 + /// + public string Province { get; set; } + /// + /// 市 + /// + public string City { get; set; } + /// + /// 县(区) + /// + public string County { get; set; } + /// + /// 具体地址 + /// + public string Address { get; set; } + /// + /// 出生日期 + /// + public DateTime Birthday { get; set; } + /// + /// 电话 + /// + public string Phone { get; set; } + /// + /// 真实姓名 + /// + public string RealName { get; set; } + /// + /// 身份证号码 + /// + public string CardNum { get; set; } + /// + /// 等级 + /// + public string Level_Id { get; set; } + /// + /// 0:正常 1停用 + /// + //[CustomValidation(typeof(DtoValidator), "Status")] + public CommonStatus Status { get; set; } + /// + /// 向外展示那个平台的信息 0:默认 1.微信 2.支付宝 + /// + public int ShowPlatformType { get; set; } + /// + /// + /// + public int IsDeleted { get; set; } + /// + /// + /// + public DateTime CreateAt { get; set; } + /// + /// + /// + public string CreateBy { get; set; } + /// + /// + /// + public DateTime DeleteAt { get; set; } + /// + /// + /// + public string DeleteBy { get; set; } + /// + /// + /// + public DateTime UpdateAt { get; set; } + /// + /// + /// + public string UpdateBy { get; set; } + /// + /// + /// + public string GroupId { get; set; } + + public List MemberTag { get; set; } + public List PlatformMemberInfos { get; set; } + + /// + /// 平台 + /// + public int PlatformType { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberInfo/Dtos/MemberTag/MemberTagQueryDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberInfo/Dtos/MemberTag/MemberTagQueryDto.cs new file mode 100644 index 0000000..87b81d2 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberInfo/Dtos/MemberTag/MemberTagQueryDto.cs @@ -0,0 +1,41 @@ + +using BPA.KitChen.StoreManagement.Application.BaseDto; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Member.MemberInfo.Dtos.MemberTag +{ + /// + /// 会员标签查询类 + /// + public class MemberTagQueryDto : PageInputBase + { + /// + /// 编号 + /// + public string Id { get; set; } + /// + /// 会员标签名称 + /// + public string Name { get; set; } + /// + /// 平台标签 0:默认 1.微信 2.支付宝 + /// + public string PlatformType { get; set; } + /// + /// 排序 + /// + public int Sort { get; set; } + /// + /// 创建时间 + /// + public DateTime? CreateAt { get; set; } + /// + /// 状态 + /// + public int? Status { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberInfo/Dtos/MemberTagAndInfoOutDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberInfo/Dtos/MemberTagAndInfoOutDto.cs new file mode 100644 index 0000000..34b1d86 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberInfo/Dtos/MemberTagAndInfoOutDto.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.OneCard.StoredValueCard.Dto +{ + public class MemberTagAndInfoOutDto + { + public string Id { get; set; } + + public string Name { get; set; } + + public string MemberTagInfoId { get; set; } + + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberInfo/Dtos/MemberTagOutDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberInfo/Dtos/MemberTagOutDto.cs new file mode 100644 index 0000000..e5b15eb --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberInfo/Dtos/MemberTagOutDto.cs @@ -0,0 +1,29 @@ +using BPA.KitChen.StoreManagement.Core.Enum; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.OneCard.StoredValueCard.Dto +{ + public class MemberTagOutDto + { + public string Id { get; set; } + /// + /// 会员标签名称 + /// + public string Name { get; set; } + /// + /// 排序 + /// + public int Sort { get; set; } + /// + /// 向外展示那个平台的信息 0:默认 1.微信 2.支付宝 + /// + public PlatformType PlatformType { get; set; } + + public string MemberId { get; set; } + + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberInfo/Dtos/PlatformMemberInfoBaseDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberInfo/Dtos/PlatformMemberInfoBaseDto.cs new file mode 100644 index 0000000..a7c15f5 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberInfo/Dtos/PlatformMemberInfoBaseDto.cs @@ -0,0 +1,121 @@ + +using BPA.KitChen.StoreManagement.Core.Enum; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.OneCard.StoredValueCard.Dto +{ + public class PlatformMemberInfoBaseDto + { + /// + /// + /// + public string Id { get; set; } + /// + /// + /// + public string NickName { get; set; } + /// + /// 0=未知 1=男 2=女 + /// + public int Sex { get; set; } + /// + /// 头像 + /// + public string HeadImgUrl { get; set; } + /// + /// 国家 + /// + public string Country { get; set; } + /// + /// 省 + /// + public string Province { get; set; } + /// + /// 市 + /// + public string City { get; set; } + /// + /// 县(区) + /// + public string County { get; set; } + /// + /// 具体地址 + /// + public string Address { get; set; } + /// + /// 出生日期 + /// + public DateTime Birthday { get; set; } + /// + /// 电话 + /// + public string Phone { get; set; } + /// + /// 真实姓名 + /// + public string RealName { get; set; } + /// + /// 身份证号码 + /// + public string CardNum { get; set; } + /// + /// 等级 + /// + public string Level_Id { get; set; } + /// + /// 0:正常 1停用 + /// + public int Status { get; set; } + /// + /// 1.微信 2.支付宝 + /// + public PlatformType PlatformType { get; set; } + /// + /// 平台会员ID + /// + public string PlatformMemberId { get; set; } + /// + /// 基础会员表ID + + /// + public string MemberInfo_Id { get; set; } + /// + /// + /// + public int IsDeleted { get; set; } + /// + /// + /// + public DateTime CreateAt { get; set; } + /// + /// + /// + public string CreateBy { get; set; } + /// + /// + /// + public DateTime DeleteAt { get; set; } + /// + /// + /// + public string DeleteBy { get; set; } + /// + /// + /// + public DateTime UpdateAt { get; set; } + /// + /// + /// + public string UpdateBy { get; set; } + /// + /// + /// + public string GroupId { get; set; } + + public List MemberTag { get; set; } +} +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberInfo/Dtos/UpdateMemberTagInputDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberInfo/Dtos/UpdateMemberTagInputDto.cs new file mode 100644 index 0000000..7400e82 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberInfo/Dtos/UpdateMemberTagInputDto.cs @@ -0,0 +1,26 @@ +using BPA.Kitchen.Core.Common; +using BPA.KitChen.StoreManagement.Application.BaseDto; +using BPA.KitChen.StoreManagement.Core.Enum; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Member.MemberInfo.Dtos +{ + public class UpdateMemberTagInputDto + { + + [CustomValidation(typeof(DtoValidator), "Member")] + public string MemberInfo_Id { get; set; } + + [CustomValidation(typeof(DtoValidator), "MemberPlatformType")] + public PlatformType PlatformType { get; set; } + + [CustomValidation(typeof(DtoValidator), "MemberTagList")] + public List Tags { get; set; } + + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberInfo/IMemberInfoService.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberInfo/IMemberInfoService.cs new file mode 100644 index 0000000..604ccfe --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberInfo/IMemberInfoService.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Member.MemberInfo +{ + public interface IMemberInfoService + { + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberInfo/MemberInfoService.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberInfo/MemberInfoService.cs new file mode 100644 index 0000000..e404fe0 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberInfo/MemberInfoService.cs @@ -0,0 +1,469 @@ +using Furion.DatabaseAccessor; +using Furion.FriendlyException; +using Furion; +using Microsoft.AspNetCore.Mvc; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Furion.DependencyInjection; +using Furion.DynamicApiController; +using Mapster; +using BPA.KitChen.StoreManagement.SqlSugar; +using BPA.KitChen.StoreManagement.Application.BaseDto; +using BPA.KitChen.StoreManagement.Application.Service.ShopManage.Member.MemberInfo.Dtos; +using BPA.KitChen.StoreManagement.Core.Entity; +using BPA.KitChen.StoreManagement.Application.Service.OneCard.StoredValueCard.Dto; +using BPA.KitChen.StoreManagement.Core.Enum; +using BPA.KitChen.StoreManagement.Application.Service.ShopManage.Member.MemberInfo.Dtos.MemberTag; +using BPA.KitChen.StoreManagement.Core.Common.Const; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Member.MemberInfo +{ + [ApiDescriptionSettings("会员管理", Tag = "会员信息")] + public class MemberInfoService : SupperRepository, IDynamicApiController, IMemberInfoService, ITransient + { + + private readonly SqlSugarScope db; + + public MemberInfoService() + { + db = SqlSugarDb.Db; // 推荐操作 + } + + /// + /// 查询会员 + /// + /// + /// + [HttpPost("/api/MemberInfoService/GetMemberPageQuery")] + public async Task GetMemberPageQuery(GetMemberInfoQueryInputDto inputDto) + { + + List conModels = new List(); + if (!string.IsNullOrEmpty(inputDto.NickName)) + { + conModels.Add(new ConditionalModel() { FieldName = "NickName", ConditionalType = ConditionalType.Like, FieldValue = inputDto.NickName }); + } + if (!string.IsNullOrEmpty(inputDto.RealName)) + { + conModels.Add(new ConditionalModel() { FieldName = "RealName", ConditionalType = ConditionalType.Like, FieldValue = inputDto.RealName }); + } + if (!string.IsNullOrEmpty(inputDto.Status)) + { + conModels.Add(new ConditionalModel() { FieldName = "Status", ConditionalType = ConditionalType.Equal, FieldValue = inputDto.Status }); + } + var result = new List(); + int total = 0; + //分页查询基础会员表 + var data = db.Queryable().Where(conModels) + .WhereIF(!string.IsNullOrWhiteSpace(inputDto.Phone), x => x.Phone.Contains(inputDto.Phone)) + .OrderBy(x => x.CreateAt, OrderByType.Desc) + .ToPageList(inputDto.Current, inputDto.PageSize, ref total); + + result = data.Adapt>(); + var tatalId = data.Select(x => x.Id).ToList(); + + //查询平台数据 + var platformMemberInfos = await db.Queryable().Where(x => tatalId.Contains(x.MemberInfo_Id)).ToListAsync(); + + //查询标签 + var tags = db.Queryable((a, b) => new JoinQueryInfos( + JoinType.Left, b.Id == a.MemberTag_Id + )).Where((a, b) => tatalId.Contains(a.MemberInfo_Id) && a.IsDeleted == 0) + .OrderBy((a, b) => a.CreateAt,OrderByType.Desc) + .Select((a, b) => new MemberTagOutDto() + { + Id = b.Id, + Name = b.Name, + Sort = b.Sort, + MemberId = a.MemberInfo_Id, + PlatformType = a.PlatformType + }) + .ToList(); + + + foreach (var item in result) + { + var tag = tags.Where(x => x.MemberId == item.Id).ToList(); + item.MemberTag = tag.Where(x => x.PlatformType == 0).ToList(); + + var re = platformMemberInfos.Where(x => x.MemberInfo_Id == item.Id).ToList(); + if (re.Count > 0) + { + + var platformMember = re.Adapt>(); + + platformMember.ForEach(obj => + { + + obj.MemberTag = tag.Where(x => x.PlatformType == obj.PlatformType).ToList(); + + }); + item.PlatformMemberInfos = platformMember; + } + else + { + item.PlatformMemberInfos = new List(); + } + } + + return new PageUtil() + { + Data = result, + Total = total + }; + } + + /// + /// 添加会员 + /// + /// + /// + [HttpPost("/api/MemberInfoService/AddMember")] + public async Task AddMember(CreateOrUpdateMemberInfoInputDto inputDto) + { + try + { + var result = true; + db.Ado.BeginTran(); + var memberInfo = await db.Queryable().FirstAsync(x => x.Phone == inputDto.Phone); + if (memberInfo == null) + { + //添加会员信息 + memberInfo = inputDto.Adapt(); + await db.Insertable(memberInfo).CallEntityMethod(m => m.Create()).ExecuteCommandAsync(); + } + + inputDto.MemberInfo_Id = memberInfo.Id; + //添加平台会员 + result = await AddPlatformMember(inputDto); + + ////添加会员账户 + //result = await AddMemberAccount(memberInfo.Id); + + db.Ado.CommitTran(); + return result; + } + catch (Exception e) + { + db.Ado.RollbackTran(); + return false; + } + } + + + /// + /// 修改会员信息 + /// + /// + [HttpPost("/api/MemberInfoService/UpdateMemberInfo")] + public async Task UpdateMemberInfo(CreateOrUpdateMemberInfoInputDto inputDto) + { + if (inputDto.PlatformType == 0) + { + var data = db.Queryable().First(x => x.Id == inputDto.MemberInfo_Id); + + if (data == null) + { + throw Oops.Oh($"会员不存在"); + } + data.Address = inputDto.Address; + data.Birthday = inputDto.Birthday; + data.CardNum = inputDto.CardNum; + data.City = inputDto.City; + data.Country = inputDto.Country; + data.County = inputDto.County; + data.HeadImgUrl = inputDto.HeadImgUrl; + data.Level_Id = inputDto.Level_Id; + data.NickName = inputDto.NickName; + data.Phone = inputDto.Phone; + data.Province = inputDto.Province; + data.RealName = inputDto.RealName; + data.Sex = inputDto.Sex; + data.Status = inputDto.Status; + data.ShowPlatformType = (int)inputDto.ShowPlatformType; + ////添加会员账户 + //await AddMemberAccount(data.Id); + return await db.Updateable(data).CallEntityMethod(m => m.Modify()).ExecuteCommandAsync() > 0; + } + else + { + + var data = db.Queryable().Where(x => x.MemberInfo_Id == inputDto.MemberInfo_Id && x.PlatformType == inputDto.PlatformType).First(); + if (data == null) + { + throw Oops.Oh($"当前平台会员不存在"); + } + data.Address = inputDto.Address; + data.Birthday = inputDto.Birthday; + data.CardNum = inputDto.CardNum; + data.City = inputDto.City; + data.Country = inputDto.Country; + data.County = inputDto.County; + data.HeadImgUrl = inputDto.HeadImgUrl; + data.Level_Id = inputDto.Level_Id; + data.NickName = inputDto.NickName; + data.Phone = inputDto.Phone; + data.Province = inputDto.Province; + data.RealName = inputDto.RealName; + data.Sex = inputDto.Sex; + data.Status = inputDto.Status; + return await db.Updateable(data).CallEntityMethod(m => m.Modify()).ExecuteCommandAsync() > 0; + } + + + + } + + + /// + /// 获取所有会员标签,获取当前会员的绑定标签 + /// + /// 会员ID + /// 0:系统平台 1.微信平台 2.支付宝平台 + /// + [HttpGet("/api/MemberInfoService/GetMemberTagAndInfo")] + public async Task> GetMemberTagAndInfo(string memberInfoId, PlatformType PlatformType) + { + var data = await db.Queryable() + .Where(x => x.IsDeleted == 0 && x.PlatformType == (int)PlatformType) + .Select(x => new MemberTagAndInfoOutDto() + { + Id = x.Id, + Name = x.Name + }).ToListAsync(); + var memberTagInfo = db.Queryable() + .Where(x => x.IsDeleted == 0 && x.MemberInfo_Id == memberInfoId && x.PlatformType == PlatformType).ToList(); + + foreach (var item in data) + { + var entity = memberTagInfo.FirstOrDefault(x => x.MemberTag_Id == item.Id); + + if (entity != null) + { + item.MemberTagInfoId = entity.Id; + } + } + + return data; + } + + + /// + /// 根据ID获取会员其他平台的信息 + /// + /// + /// + [HttpGet("/api/MemberInfoService/GetPlatformMemberList")] + public async Task> GetPlatformMemberList(string memberId) + { + var data = await db.Queryable().Where(x => x.MemberInfo_Id == memberId).ToListAsync(); + var platformMember = data.Adapt>(); + + //查询标签 + var tags = db.Queryable((a, b) => new JoinQueryInfos( + JoinType.Left, b.Id == a.MemberTag_Id + )).Where((a, b) => memberId == a.MemberInfo_Id && a.IsDeleted == 0) + .Select((a, b) => new MemberTagOutDto() + { + Id = b.Id, + Name = b.Name, + Sort = b.Sort, + MemberId = a.MemberInfo_Id, + PlatformType = a.PlatformType + }) + .ToList(); + platformMember.ForEach(obj => + { + obj.MemberTag = tags.Where(x => x.PlatformType == obj.PlatformType).ToList(); + }); + + + return platformMember.Adapt>(); + } + + + + + + /// + /// 查询会员标签信息 + /// + /// + /// + [HttpPost("/api/MemberInfoService/GetMemberTag")] + public PageUtil GetMemberTag(MemberTagQueryDto dto) + { + List conModels = new List(); + + string groupId = App.User.FindFirst(ClaimConst.GroupId)?.Value; + if (!string.IsNullOrEmpty(dto.Name)) + { + conModels.Add(new ConditionalModel() { FieldName = "Name", ConditionalType = ConditionalType.Equal, FieldValue = dto.Name.ToString() }); + } + if (!string.IsNullOrEmpty(dto.PlatformType)) + { + conModels.Add(new ConditionalModel() { FieldName = "PlatformType", ConditionalType = ConditionalType.Equal, FieldValue = dto.PlatformType }); + } + if (!string.IsNullOrEmpty(dto.Status.ToString())) + { + conModels.Add(new ConditionalModel() { FieldName = "Status", ConditionalType = ConditionalType.Equal, FieldValue = dto.Status.ToString() }); + } + int total = new RefAsync(); + var res = db.Queryable() + .Where(a => a.IsDeleted == 0) + .Where(conModels) + .WhereIF(dto.CreateAt.HasValue, a => SqlFunc.DateIsSame(a.CreateAt, Convert.ToDateTime(dto.CreateAt), DateType.Day)) + .OrderBy(x => x.CreateAt, OrderByType.Desc) + .Select(t => new MemberTagQueryDto + { + Id = t.Id, + Name = t.Name, + Sort = t.Sort, + PlatformType = t.PlatformType.ToString(), + CreateAt = t.CreateAt, + Status = Convert.ToInt32(t.Status), + + }).ToPageList(dto.Current, dto.PageSize, ref total); + return new PageUtil() + { + Data = res, + Total = total + }; + } + + + /// + /// 修改会员状态 + /// + /// + [HttpPost("/api/MemberInfoService/UpdateMemberStatus")] + public async Task UpdateMemberStatus(MemberInfoBaseDto inputDto) + { + if (!System.Enum.IsDefined(typeof(PlatformType), inputDto.PlatformType)) + { + throw Oops.Oh($"平台错误"); + } + + try + { + db.BeginTran(); + var data = db.Queryable().First(x => x.Id == inputDto.Id); + var data2 = db.Queryable().Where(x => x.MemberInfo_Id == inputDto.Id).ToList(); + if (data == null) + { + throw Oops.Oh($"会员不存在"); + } + if (inputDto.PlatformType == 0) + { + data.Status = (CommonStatus)inputDto.Status; + db.Updateable(data).CallEntityMethod(m => m.Modify()).ExecuteCommand(); + } + if (data2.Count > 0) + { + //根据选择平台修改会员状态 + data2 = data2.Where(x => inputDto.PlatformType == 1 ? (x.PlatformType == 1) : (x.PlatformType == 2 ? (x.PlatformType == 2) : true)).ToList(); + data2.ForEach(item => + { + item.Status = (CommonStatus)inputDto.Status; + }); + db.Updateable(data2).CallEntityMethod(m => m.Modify()).ExecuteCommand(); + } + db.CommitTran(); + return await Task.FromResult(true); + } + catch (Exception ex) + { + db.RollbackTran(); + //BPALog.WriteLog(msg + ":" + ex.Message, LogEnum.Error, null, ex); + throw Oops.Oh(ex.Message); + } + } + + + /// + /// 修改会员标签 + /// + /// + /// + [HttpPost("/api/MemberInfoService/UpdateMemberTag")] + public async Task UpdateMemberTag(UpdateMemberTagInputDto inputDto) + { + + try + { + db.BeginTran(); + //查询当前会员绑定的标签 + var data = db.Queryable() + .Where(x => x.MemberInfo_Id == inputDto.MemberInfo_Id + && inputDto.PlatformType == x.PlatformType + ).ToList(); + data.ForEach(item => + { + item.IsDeleted = 1; + }); + //全部删除 + db.Deleteable(data).ExecuteCommand(); + + //添加会员标签 + foreach (var item in inputDto.Tags) + { + db.Insertable(new BPA_MemberTagInfo() + { + PlatformType = inputDto.PlatformType, + MemberInfo_Id = inputDto.MemberInfo_Id, + MemberTag_Id = item + + }).CallEntityMethod(m => m.Create()).ExecuteCommand(); + } + db.CommitTran(); + return await Task.FromResult(true); + } + catch (Exception ex) + { + db.RollbackTran(); + //BPALog.WriteLog(msg + ":" + ex.Message, LogEnum.Error, null, ex); + throw Oops.Oh(ex.Message); + } + } + + + + /// + /// 添加平台会员 + /// + /// + /// + private async Task AddPlatformMember(CreateOrUpdateMemberInfoInputDto inputDto) + { + var memberInfo = db.Queryable().First(x => + x.MemberInfo_Id == inputDto.MemberInfo_Id && x.PlatformType == inputDto.PlatformType); + if (memberInfo != null) return false; + var member = new BPA_PlatformMemberInfo() + { + Address = inputDto.Address, + Birthday = inputDto.Birthday, + CardNum = inputDto.CardNum, + City = inputDto.City, + Country = inputDto.Country, + County = inputDto.County, + HeadImgUrl = inputDto.HeadImgUrl, + Level_Id = inputDto.Level_Id, + MemberInfo_Id = inputDto.MemberInfo_Id, + NickName = inputDto.NickName, + Phone = inputDto.Phone, + PlatformMemberId = Guid.NewGuid().ToString(), + PlatformType = inputDto.PlatformType, + Province = inputDto.Province, + RealName = inputDto.RealName, + Sex = inputDto.Sex, + Status = inputDto.Status, + }; + return await db.Insertable(member).CallEntityMethod(m => m.Create()).ExecuteCommandAsync() > 0; + + } + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberTag/Dtos/MemberTagDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberTag/Dtos/MemberTagDto.cs new file mode 100644 index 0000000..eb7b6be --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberTag/Dtos/MemberTagDto.cs @@ -0,0 +1,36 @@ + +using System.ComponentModel.DataAnnotations; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Member.MemberTag.Dtos +{ + /// + /// MemberTagDto + /// + public class MemberTagDto + { + /// + /// 编号 + /// + public string Id { get; set; } + /// + /// 会员标签名称 + /// + [Required] + public string Name { get; set; } + /// + /// 排序 + /// + //[Range(0, int.MaxValue, ErrorMessage = "排序必须大于0")] + public int Sort { get; set; } = 0; + /// + /// 平台标签 0:默认 1.微信 2.支付宝 + /// + //[Range(0, 4, ErrorMessage = "平台标签只能输入0,1,2")] + public int PlatformType { get; set; } + /// + /// 状态 + /// + //[Range(0, 1, ErrorMessage = "状态只能输入0或者1")] + public int Status { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberTag/IMemberTagService.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberTag/IMemberTagService.cs new file mode 100644 index 0000000..9459a55 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberTag/IMemberTagService.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Member.MemberTag +{ + public interface IMemberTagService + { + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberTag/MemberTagService.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberTag/MemberTagService.cs new file mode 100644 index 0000000..7322702 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Member/MemberTag/MemberTagService.cs @@ -0,0 +1,163 @@ +using BPA.KitChen.StoreManagement.Application.BaseDto; +using BPA.KitChen.StoreManagement.Application.Service.ShopManage.Member.MemberInfo.Dtos.MemberTag; +using BPA.KitChen.StoreManagement.Application.Service.ShopManage.Member.MemberTag.Dtos; +using BPA.KitChen.StoreManagement.Core.Common.Const; +using BPA.KitChen.StoreManagement.Core.Entity; +using BPA.KitChen.StoreManagement.Core.Enum; +using BPA.KitChen.StoreManagement.SqlSugar; +using Furion; +using Furion.DependencyInjection; +using Furion.DynamicApiController; +using Furion.FriendlyException; +using Furion.RemoteRequest; +using Microsoft.AspNetCore.Mvc; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Member.MemberTag +{ + + [ApiDescriptionSettings("会员管理", Tag = "会员标签")] + public class MemberTagService : SupperRepository, IDynamicApiController, IMemberTagService, ITransient + { + private readonly SqlSugarScope db; + + public MemberTagService() + { + db = SqlSugarDb.Db; // 推荐操作 + } + + /// + /// 查询会员标签信息 + /// + /// + /// + [HttpPost("/api/MemberTagService/MemberTagQueryDto")] + public PageUtil GetMemberTag(MemberTagQueryDto dto) + { + List conModels = new List(); + + string groupId = App.User.FindFirst(ClaimConst.GroupId)?.Value; + if (!string.IsNullOrEmpty(dto.Name)) + { + conModels.Add(new ConditionalModel() { FieldName = "Name", ConditionalType = ConditionalType.Like, FieldValue= dto.Name.ToString() }); + } + if (!string.IsNullOrEmpty(dto.PlatformType)) + { + conModels.Add(new ConditionalModel() { FieldName = "PlatformType", ConditionalType = ConditionalType.Equal, FieldValue = dto.PlatformType }); + } + if (!string.IsNullOrEmpty(dto.Status.ToString())) + { + conModels.Add(new ConditionalModel() { FieldName = "Status", ConditionalType = ConditionalType.Equal, FieldValue = dto.Status.ToString() }); + } + int total = new RefAsync(); + var res = db.Queryable() + .Where(a => a.IsDeleted == 0) + .Where(conModels) + .WhereIF(dto.CreateAt.HasValue, a => SqlFunc.DateIsSame(a.CreateAt, Convert.ToDateTime(dto.CreateAt), DateType.Day)) + .OrderBy(x => x.CreateAt, OrderByType.Desc) + .Select(t => new MemberTagQueryDto + { + Id = t.Id, + Name = t.Name, + Sort = t.Sort, + PlatformType = t.PlatformType.ToString(), + CreateAt = t.CreateAt, + Status = Convert.ToInt32(t.Status), + + }).ToPageList(dto.Current, dto.PageSize, ref total); + return new PageUtil() + { + Data = res, + Total = total + }; + } + + /// + /// 添加会员标签信息 + /// + /// + /// + [HttpPost("/api/MemberTagService/AddMemberTag")] + public async Task AddMemberTag(MemberTagDto dto) + { + var activityRecord = new BPA_MemberTag + { + Name = dto.Name, + Sort = dto.Sort, + PlatformType =(int)dto.PlatformType, + Status =(CommonStatus)dto.Status, + }; + var res = await db.Insertable(activityRecord).CallEntityMethod(m => m.Create()).ExecuteCommandAsync(); + return await Task.FromResult(res > 0); + } + + /// + /// 更新会员标签信息 + /// + /// + /// + [HttpPost("/api/MemberTagService/UpdateMemberTag")] + public async Task UpdateMemberTag(MemberTagDto dto) + { + + try + { + db.BeginTran(); + var resEntity = db.Queryable().Where(it => it.IsDeleted == 0).First(it => it.Id == dto.Id); + if (null == resEntity) + { + return false; + } + resEntity.Name = dto.Name; + resEntity.Sort = dto.Sort; + resEntity.PlatformType = (int)dto.PlatformType; + resEntity.Status =(CommonStatus) dto.Status; + //if (!string.IsNullOrEmpty(dto.Status.ToString())) + //{ + + //} + var res = db.Updateable(resEntity).IgnoreColumns(ignoreAllNullColumns: true).CallEntityMethod(m => m.Modify()).ExecuteCommand(); + + db.CommitTran(); + return await Task.FromResult(res > 0); + } + catch (Exception ex) + { + db.RollbackTran(); + //BPALog.WriteLog(msg + ":" + ex.Message, LogEnum.Error, null, ex); + throw Oops.Oh(ex.Message); + } + + + } + + + /// + /// 删除会员标签信息 + /// + /// + /// + [HttpDelete("/api/MemberTagService/DelMemberTag")] + public bool DelMemberTag(string Id) + { + // 查询数据库中是否存在未删除的活动参与记录信息 + var resEntity = db.Queryable().First(it => it.Id == Id); + if (null == resEntity) + { + return false; + } + resEntity.IsDeleted = 1; + resEntity.Status = CommonStatus.DELETED; + var res = db.Updateable(resEntity).CallEntityMethod(m => m.Delete()).ExecuteCommand(); + return res > 0; + } + + + + } +} diff --git a/BPA.KitChen.StoreManagement.Application/Service/Test/TestService.cs b/BPA.KitChen.StoreManagement.Application/Service/Test/TestService.cs index 8761602..afec990 100644 --- a/BPA.KitChen.StoreManagement.Application/Service/Test/TestService.cs +++ b/BPA.KitChen.StoreManagement.Application/Service/Test/TestService.cs @@ -23,7 +23,7 @@ namespace BPA.KitChen.StoreManagement.Application.Service.TestService var types = Assembly.Load("BPA.KitChen.StoreManagement.Core").GetTypes() .Where(x => x.Namespace != null && x.GetCustomAttribute() != null - && x.Namespace.Contains("BPA.KitChen.StoreManagement.Core.Entity")) + && x.Namespace.Contains("BPA.KitChen.StoreManagement.Core.Entity.Coupon")) .ToArray(); SqlSugarDb.Db.CodeFirst.InitTables(types); } diff --git a/BPA.KitChen.StoreManagement.Core/Entity/BPA_DevicePushRecode.cs b/BPA.KitChen.StoreManagement.Core/Entity/BPA_DevicePushRecode.cs index 28250d6..9a3420b 100644 --- a/BPA.KitChen.StoreManagement.Core/Entity/BPA_DevicePushRecode.cs +++ b/BPA.KitChen.StoreManagement.Core/Entity/BPA_DevicePushRecode.cs @@ -25,5 +25,9 @@ namespace BPA.KitChen.StoreManagement.Core.Entity [SugarColumn(ColumnDataType = "nvarchar(1000)")] public string DataResore { get; set; } + + public int DeviceAutoKey { get; set; } + public string Description { get; set; } + } } diff --git a/BPA.KitChen.StoreManagement.Core/Entity/BPA_MemberInfo.cs b/BPA.KitChen.StoreManagement.Core/Entity/BPA_MemberInfo.cs new file mode 100644 index 0000000..e78889c --- /dev/null +++ b/BPA.KitChen.StoreManagement.Core/Entity/BPA_MemberInfo.cs @@ -0,0 +1,91 @@ +using BPA.KitChen.StoreManagement.Core.Entity.Base; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Core.Entity +{ + /// + /// 会员 + /// + [SugarTable("BPA_MemberInfo")] + public class BPA_MemberInfo : IBaseGroupIdEntity + { + + /// + /// + /// + [SugarColumn(IsNullable = true)] + public string NickName { get; set; } + /// + /// 0=未知 1=男 2=女 + /// + public int Sex { get; set; } + /// + /// 头像 + /// + [SugarColumn(IsNullable = true)] + public string HeadImgUrl { get; set; } + /// + /// 国家 + /// + [SugarColumn(IsNullable = true)] + public string Country { get; set; } + /// + /// 省 + /// + [SugarColumn(IsNullable = true)] + public string Province { get; set; } + /// + /// 市 + /// + [SugarColumn(IsNullable = true)] + public string City { get; set; } + /// + /// 县(区) + /// + [SugarColumn(IsNullable = true)] + public string County { get; set; } + /// + /// 具体地址 + /// + [SugarColumn(IsNullable = true)] + public string Address { get; set; } + /// + /// 出生日期 + /// + public DateTime Birthday { get; set; } + /// + /// 电话 + /// + [SugarColumn(IsNullable = true)] + public string Phone { get; set; } + /// + /// 真实姓名 + /// + [SugarColumn(IsNullable = true)] + public string RealName { get; set; } + /// + /// 身份证号码 + /// + [SugarColumn(IsNullable = true)] + public string CardNum { get; set; } + /// + /// 等级 + /// + [SugarColumn(IsNullable = true)] + public string Level_Id { get; set; } + /// + /// 向外展示那个平台的信息 0:默认 1.微信 2.支付宝 + /// + public int ShowPlatformType { get; set; } + + /// + /// 积分 + /// + public decimal Integral { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Core/Entity/BPA_MemberTag.cs b/BPA.KitChen.StoreManagement.Core/Entity/BPA_MemberTag.cs new file mode 100644 index 0000000..be45bc6 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Core/Entity/BPA_MemberTag.cs @@ -0,0 +1,31 @@ + +using BPA.KitChen.StoreManagement.Core.Entity.Base; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Core.Entity +{ + /// + /// 会员标签 + /// + [SugarTable("BPA_MemberTag")] + public class BPA_MemberTag : IBaseGroupIdEntity + { + /// + /// 会员标签名称 + /// + public string Name { get; set; } + /// + /// 排序 + /// + public int Sort { get; set; } + /// + /// 平台标签 0:默认 1.微信 2.支付宝 + /// + public int PlatformType { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Core/Entity/BPA_MemberTagInfo.cs b/BPA.KitChen.StoreManagement.Core/Entity/BPA_MemberTagInfo.cs new file mode 100644 index 0000000..b092703 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Core/Entity/BPA_MemberTagInfo.cs @@ -0,0 +1,33 @@ + + +using BPA.KitChen.StoreManagement.Core.Entity.Base; +using BPA.KitChen.StoreManagement.Core.Enum; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Core.Entity +{ + /// + /// 平台会员标签 + /// + [SugarTable("BPA_MemberTagInfo")] + public class BPA_MemberTagInfo : IBaseGroupIdEntity + { + /// + /// 会员标签Id + /// + public string MemberTag_Id { get; set; } + /// + /// 会员编号 + /// + public string MemberInfo_Id { get; set; } + /// + /// 平台标签 0:默认 1.微信 2.支付宝 + /// + public PlatformType PlatformType { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Core/Entity/Coupon/BPA_Coupon.cs b/BPA.KitChen.StoreManagement.Core/Entity/Coupon/BPA_Coupon.cs new file mode 100644 index 0000000..50b42c9 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Core/Entity/Coupon/BPA_Coupon.cs @@ -0,0 +1,68 @@ +using BPA.KitChen.StoreManagement.Core.Entity.Base; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Core.Entity.Coupon +{ + /// + /// 优惠卷 + /// + [SugarTable("BPA_Coupon")] + public class BPA_Coupon: IBaseGroupIdEntity + { + + /// + /// 优惠券标题 + /// + public string CouponTitle { get; set; } + /// + /// 优惠券类型(1.满减优惠卷 2.代金优惠卷 3.无门槛优惠卷) + /// + public int CouponType { get; set; } + /// + /// 优惠券值(优惠金额) + /// + public decimal CouponValue { get; set; } + /// + /// 使用条件 + /// + public decimal Condition { get; set; } + /// + /// 使用时间的类型 1.时间范围内 2.固定期限 + /// + public int TimeType { get; set; } + /// + /// 固定期限值(如领取后10内有效) + /// + public int ValidFixedTerm { get; set; } + /// + /// 开始时间 + /// + public DateTime ValidStartTime { get; set; } + /// + /// 结束时间 + /// + public DateTime ValidEndTime { get; set; } + /// + /// 状态(1:生效、2:失效 3:作废 4.停用) + /// + public int ValidStatus { get; set; } + /// + /// 每人可领取数量 + /// + public int GetLimit { get; set; } + /// + /// 备注 + /// + public string Remarks { get; set; } + /// + /// 创建人类型(0.供应商 1.平台) + /// + public int CreateType { get; set; } + + } +} diff --git a/BPA.KitChen.StoreManagement.Core/Entity/Coupon/BPA_CouponCustomerStore.cs b/BPA.KitChen.StoreManagement.Core/Entity/Coupon/BPA_CouponCustomerStore.cs new file mode 100644 index 0000000..58b1ff0 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Core/Entity/Coupon/BPA_CouponCustomerStore.cs @@ -0,0 +1,20 @@ +using BPA.KitChen.StoreManagement.Core.Entity.Base; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Core.Entity.Coupon +{ + /// + /// 客户领取表与店铺关系表 + /// + [SugarTable("BPA_CouponCustomerStore")] + public class BPA_CouponCustomerStore:IBaseEntity + { + public string StoreId { get; set; } + public string Coupon_Customer_Id { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Core/Entity/Coupon/BPA_CouponGoodsRelations.cs b/BPA.KitChen.StoreManagement.Core/Entity/Coupon/BPA_CouponGoodsRelations.cs new file mode 100644 index 0000000..56a9634 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Core/Entity/Coupon/BPA_CouponGoodsRelations.cs @@ -0,0 +1,48 @@ +using BPA.KitChen.StoreManagement.Core.Common.Const; +using BPA.KitChen.StoreManagement.Core.Entity.Base; +using Furion; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Core.Entity.Coupon +{ + /// + /// 优惠卷记录与区域店铺供应商关联关系表 + /// + [SugarTable("BPA_CouponGoodsRelations")] + public class BPA_CouponGoodsRelations : IBaseGroupIdEntity + { + /// + /// 范围Id + /// + [SugarColumn(ColumnDataType = "Nvarchar(64)", IsNullable = false)] + public string Coupon_Range_Id { get; set; } + /// + /// 商品Id + /// + [SugarColumn(ColumnDataType = "Nvarchar(64)", IsNullable = false)] + public string GoodsId { get; set; } + /// + /// 备注 + /// + [SugarColumn(ColumnDataType = "Nvarchar(255)", IsNullable = true)] + public string Remark { get; set; } + /// + /// 新增 + /// + public void Create() + { + var userId = App.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value; + this.Id = Guid.NewGuid().ToString(); + this.CreateAt = DateTime.Now; + if (!string.IsNullOrEmpty(userId)) + { + this.CreateBy = userId; + } + } + } +} diff --git a/BPA.KitChen.StoreManagement.Core/Entity/Coupon/BPA_CouponLog.cs b/BPA.KitChen.StoreManagement.Core/Entity/Coupon/BPA_CouponLog.cs new file mode 100644 index 0000000..34f8374 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Core/Entity/Coupon/BPA_CouponLog.cs @@ -0,0 +1,50 @@ +using BPA.KitChen.StoreManagement.Core.Entity.Base; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Core.Entity.Coupon +{ + [SugarTable("BPA_CouponLog")] + public class BPA_CouponLog : IBaseEntity + { + /// + /// 订单Id + /// + [SugarColumn(ColumnDataType = "Nvarchar(64)", IsNullable = true)] + public string OrderId { get; set; } + /// + /// 客户Id -- 微信的OpenId + /// + [SugarColumn(ColumnDataType = "Nvarchar(64)", IsNullable = true)] + public string CustomerId { get; set; } + /// + /// 0表示退单反券 1表示订单完成 + /// + [SugarColumn(ColumnDataType = "INT", IsNullable = true)] + public int OrderType { get; set; } + /// + /// 券Id + /// + [SugarColumn(ColumnDataType = "Nvarchar(64)", IsNullable = true)] + public string CouponId { get; set; } + /// + /// 备注 + /// + [SugarColumn(ColumnDataType = "Nvarchar(255)", IsNullable = true)] + public string Remark { get; set; } + /// + /// 订单时间 + /// + [SugarColumn(ColumnDataType = "DATETIME", IsNullable = true)] + public DateTime OrderTime { get; set; } + /// + /// 客户领券表Id + /// + [SugarColumn(ColumnDataType = "Nvarchar(64)", IsNullable = true)] + public string Coupon_Customer_Id { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Core/Entity/Coupon/BPA_CouponRange.cs b/BPA.KitChen.StoreManagement.Core/Entity/Coupon/BPA_CouponRange.cs new file mode 100644 index 0000000..31df4ff --- /dev/null +++ b/BPA.KitChen.StoreManagement.Core/Entity/Coupon/BPA_CouponRange.cs @@ -0,0 +1,89 @@ +using BPA.KitChen.StoreManagement.Core.Common.Const; +using BPA.KitChen.StoreManagement.Core.Entity.Base; +using Furion; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Core.Entity.Coupon +{ + /// + /// 优惠券发放记录表 + /// + [SugarTable("BPA_CouponRange")] + public class BPA_CouponRange : IBaseGroupIdEntity + { + /// + /// 发放数量 + /// + [SugarColumn(ColumnDataType = "INT", IsNullable = false)] + public int SendNum { get; set; } + /// + /// 批次号 + /// + [SugarColumn(ColumnDataType = "Nvarchar(64)", IsNullable = true)] + public string BatchNo { get; set; } + /// + /// 优惠券Id + /// + [SugarColumn(ColumnDataType = "Nvarchar(64)", IsNullable = false)] + public string Coupon_Id { get; set; } + /// + /// 适用范围类型 1.店铺 2.供应商 3.区域 + /// + [SugarColumn(ColumnDataType = "INT", IsNullable = false)] + public int RangeType { get; set; } + /// + /// 创建人类型(0.供应商 1.平台) + /// + [SugarColumn(ColumnDataType = "INT", IsNullable = false)] + public int CreateType { get; set; } + /// + /// 备注 + /// + [SugarColumn(ColumnDataType = "Nvarchar(255)", IsNullable = true)] + public string Remark { get; set; } + /// + /// 新增 + /// + public void Create() + { + var userId = App.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value; + this.Id = Guid.NewGuid().ToString(); + this.CreateAt = DateTime.Now; + if (!string.IsNullOrEmpty(userId)) + { + this.CreateBy = userId; + } + } + /// + /// 修改 + /// + public void Modify() + { + var userId = App.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value; + this.UpdateAt = DateTime.Now; + if (!string.IsNullOrEmpty(userId)) + { + this.UpdateBy = userId; + } + } + + /// + /// 删除 + /// + public void Delete() + { + var userId = App.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value; + this.DeleteAt = DateTime.Now; + if (!string.IsNullOrEmpty(userId)) + { + this.DeleteBy = userId; + } + } + + } +} diff --git a/BPA.KitChen.StoreManagement.Core/Entity/Coupon/BPA_CouponRangeRelations.cs b/BPA.KitChen.StoreManagement.Core/Entity/Coupon/BPA_CouponRangeRelations.cs new file mode 100644 index 0000000..417b5e8 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Core/Entity/Coupon/BPA_CouponRangeRelations.cs @@ -0,0 +1,43 @@ +using BPA.KitChen.StoreManagement.Core.Common.Const; +using BPA.KitChen.StoreManagement.Core.Entity.Base; +using Furion; +using SqlSugar; + +namespace BPA.KitChen.StoreManagement.Core.Entity.Coupon +{ + /// + /// 优惠卷记录与区域店铺供应商关联关系表 + /// + [SugarTable("BPA_CouponRangeRelations")] + public class BPA_CouponRangeRelations : IBaseGroupIdEntity + { + /// + /// 范围Id + /// + [SugarColumn(ColumnDataType = "Nvarchar(64)", IsNullable = false)] + public string Coupon_Range_Id { get; set; } + /// + /// 店铺Id,区域id或供应商id + /// + [SugarColumn(ColumnDataType = "Nvarchar(64)", IsNullable = false)] + public string RangeTypeId { get; set; } + /// + /// 备注 + /// + [SugarColumn(ColumnDataType = "Nvarchar(255)", IsNullable = true)] + public string Remark { get; set; } + /// + /// 新增 + /// + public void Create() + { + var userId = App.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value; + this.Id = Guid.NewGuid().ToString(); + this.CreateAt = DateTime.Now; + if (!string.IsNullOrEmpty(userId)) + { + this.CreateBy = userId; + } + } + } +} diff --git a/BPA.KitChen.StoreManagement.Core/Entity/Coupon/BPA_CustomerCoupon.cs b/BPA.KitChen.StoreManagement.Core/Entity/Coupon/BPA_CustomerCoupon.cs new file mode 100644 index 0000000..e70a837 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Core/Entity/Coupon/BPA_CustomerCoupon.cs @@ -0,0 +1,110 @@ +using Furion; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using BPA.KitChen.StoreManagement.Core.Common.Const; +using BPA.KitChen.StoreManagement.Core.Entity.Base; + +namespace BPA.KitChen.StoreManagement.Core.Entity.Coupon +{ + /// + /// 顾客优惠券 + /// + [SugarTable("BPA_CustomerCoupon")] + public class BPA_CustomerCoupon: IBaseGroupIdEntity + { + /// + /// 客户Id + /// + [SugarColumn(ColumnDataType = "Nvarchar(64)",IsNullable =false)] + public string Customer_Id { get; set; } + /// + /// 订单Id + /// + [SugarColumn(ColumnDataType = "Nvarchar(64)", IsNullable = true)] + public string Order_Id { get; set; } + /// + /// 领取方式(1.小程序领取 2.线下门店扫码 3.活动自动下发 4.好友分享领取 5.指定发放) + /// + [SugarColumn(ColumnDataType = "INT", IsNullable = false,ColumnName = "ReceiveType")] + public int Receive_Type { get; set; } + /// + /// 优惠券Id + /// + [SugarColumn(ColumnDataType = "Nvarchar(64)", IsNullable = false)] + public string Coupon_Id { get; set; } + /// + /// 状态(1:未使用 2.已核销 3.占用中 4.失效) + /// + [SugarColumn(ColumnDataType = "INT", IsNullable = true)] + public int State { get; set; } + /// + /// 开始时间 + /// + [SugarColumn(ColumnDataType = "DATETIME", IsNullable = false,ColumnName = "ValidStartTime")] + public DateTime Valid_StartTime { get; set; } + + /// + /// 结束时间 + /// + [SugarColumn(ColumnDataType = "DATETIME", IsNullable = false, ColumnName = "ValidEndTime")] + public DateTime Valid_EndTime { get; set; } + /// + /// 核销时间 + /// + [SugarColumn(ColumnDataType = "DATETIME", IsNullable = true)] + public DateTime? WriteOffTime { get; set; } + /// + /// 范围Id + /// + [SugarColumn(ColumnDataType = "Nvarchar(64)", IsNullable = false)] + public string Coupon_Range_Id { get; set; } + /// + /// 用户手机号 + /// + [SugarColumn(ColumnDataType = "Nvarchar(64)", IsNullable = true)] + public string CustomerPhone { get; set; } + + /// + /// 新增 + /// + public void Create() + { + var userId = App.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value; + this.Id = Guid.NewGuid().ToString(); + if (!string.IsNullOrEmpty(userId)) + { + this.CreateBy = userId; + } + } + /// + /// 修改 + /// + public void Modify() + { + var userId = App.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value; + this.UpdateAt = DateTime.Now; + if (!string.IsNullOrEmpty(userId)) + { + this.UpdateBy = userId; + } + } + + /// + /// 删除 + /// + public void Delete() + { + var userId = App.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value; + this.DeleteAt = DateTime.Now; + if (!string.IsNullOrEmpty(userId)) + { + this.DeleteBy = userId; + } + } + + } +} diff --git a/BPA.KitChen.StoreManagement.Core/Entity/Coupon/BPA_GoodsCoupon.cs b/BPA.KitChen.StoreManagement.Core/Entity/Coupon/BPA_GoodsCoupon.cs new file mode 100644 index 0000000..e77c204 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Core/Entity/Coupon/BPA_GoodsCoupon.cs @@ -0,0 +1,50 @@ +using BPA.KitChen.StoreManagement.Core.Entity.Base; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Core.Entity.Coupon +{ + + [SugarTable("BPA_GoodsCoupon")] + public class BPA_GoodsCoupon: IBaseEntity + { + /// + /// 商品id + /// + public string GoodsId { get; set; } + public string StoreId { get; set; } + /// + /// 标题 + /// + public string Title { get; set; } + /// + /// 商品名称 + /// + public string GoodsName { get; set; } + /// + /// 类型(平台)id + /// + public string CTypeId { get; set; } + /// + /// 原始金额 + /// + public decimal Money { get; set; } + /// + /// 平台金额 + /// + public decimal SoureMoney { get; set; } + /// + /// 加盟商id + /// + public string GroupId { get; set; } + public DateTime CrateTimeAt { get; set; } + /// + /// 是否启用 + /// + public bool Enable { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Core/Entity/Coupon/BPA_GoodsCouponWriteoffLog.cs b/BPA.KitChen.StoreManagement.Core/Entity/Coupon/BPA_GoodsCouponWriteoffLog.cs new file mode 100644 index 0000000..ac98a0d --- /dev/null +++ b/BPA.KitChen.StoreManagement.Core/Entity/Coupon/BPA_GoodsCouponWriteoffLog.cs @@ -0,0 +1,27 @@ +using BPA.KitChen.StoreManagement.Core.Entity.Base; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Core.Entity.Coupon +{ + + [SugarTable("bpa_goodscouponwriteofflog")] + public class BPA_GoodsCouponWriteoffLog : IBaseGroupIdEntity + { + /// + /// 订单ID + /// + [SugarColumn(ColumnDataType = "Nvarchar(64)", IsNullable = true)] + public string OrderId { get; set; } + + /// + /// 优惠券ID + /// + [SugarColumn(ColumnDataType = "Nvarchar(64)", IsNullable = true)] + public string GoodsCouponId { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Core/Entity/Coupon/BPA_PaperCoupon.cs b/BPA.KitChen.StoreManagement.Core/Entity/Coupon/BPA_PaperCoupon.cs new file mode 100644 index 0000000..3b5b230 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Core/Entity/Coupon/BPA_PaperCoupon.cs @@ -0,0 +1,40 @@ +using BPA.KitChen.StoreManagement.Core.Entity.Base; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Core.Entity.Coupon +{ + /// + /// 纸质优惠卷 + /// + [SugarTable("bpa_papercoupon")] + public class BPA_PaperCoupon: IBaseEntity + { + /// + /// 标题 + /// + public string Title { get; set; } + /// + /// 类型 + /// + public string CTypeId { get; set; } + /// + /// 金额 + /// + public decimal Money { get; set; } + /// + /// 平台金额 + /// + public decimal SoureMoney { get; set; } + /// + /// 创建时间 + /// + public DateTime CrateTimeAt { get; set; } + public string GroupId { get; set; } + public bool Enable { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Core/Entity/Coupon/BPA_PaperCouponType.cs b/BPA.KitChen.StoreManagement.Core/Entity/Coupon/BPA_PaperCouponType.cs new file mode 100644 index 0000000..810a5c4 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Core/Entity/Coupon/BPA_PaperCouponType.cs @@ -0,0 +1,22 @@ +using BPA.KitChen.StoreManagement.Core.Entity.Base; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Core.Entity.Coupon +{ + /// + /// 纸质优惠卷类型 + /// + [SugarTable("bpa_papercoupontype")] + public class BPA_PaperCouponType: IBaseEntity + { + /// + /// 类型名称 + /// + public string Name { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Core/Entity/Coupon/BPA_PaperCouponWriteoffLog.cs b/BPA.KitChen.StoreManagement.Core/Entity/Coupon/BPA_PaperCouponWriteoffLog.cs new file mode 100644 index 0000000..a4a2bb8 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Core/Entity/Coupon/BPA_PaperCouponWriteoffLog.cs @@ -0,0 +1,27 @@ +using BPA.KitChen.StoreManagement.Core.Entity.Base; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Core.Entity.Coupon +{ + + [SugarTable("BPA_PaperCouponWriteoffLog")] + public class BPA_PaperCouponWriteoffLog : IBaseGroupIdEntity + { + /// + /// 订单ID + /// + [SugarColumn(ColumnDataType = "Nvarchar(64)", IsNullable = true)] + public string OrderId { get; set; } + + /// + /// 优惠券ID + /// + [SugarColumn(ColumnDataType = "Nvarchar(64)", IsNullable = true)] + public string PaperCouponId { get; set; } + } +} diff --git a/BPA.KitChen.StoreManagement.Core/Enum/E_CouponGitType.cs b/BPA.KitChen.StoreManagement.Core/Enum/E_CouponGitType.cs new file mode 100644 index 0000000..e5b43dc --- /dev/null +++ b/BPA.KitChen.StoreManagement.Core/Enum/E_CouponGitType.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Core.Enum +{ + public enum E_CouponGitType + { + 小程序领取 = 1, + 线下门店扫码 = 2, + 活动下发 = 3, + 好友分享领取 = 4, + 指定领取 = 5, + 参与活动 = 6, + 商城兑换=7, + + } +} diff --git a/BPA.KitChen.StoreManagement.Core/Enum/E_CouponStatus.cs b/BPA.KitChen.StoreManagement.Core/Enum/E_CouponStatus.cs new file mode 100644 index 0000000..5fe3c33 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Core/Enum/E_CouponStatus.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Core.Enum +{ + public enum E_CouponStatus + { + + /// + /// 生效 + /// + [Description("生效")] + 生效=1, + /// + /// 生效 + /// + [Description("失效")] + 失效 = 2, + /// + /// 作废 + /// + [Description("作废")] + 作废 =3 + } +} diff --git a/BPA.KitChen.StoreManagement.Core/Enum/E_CouponType.cs b/BPA.KitChen.StoreManagement.Core/Enum/E_CouponType.cs new file mode 100644 index 0000000..60c3267 --- /dev/null +++ b/BPA.KitChen.StoreManagement.Core/Enum/E_CouponType.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.KitChen.StoreManagement.Core.Enum +{ + public enum E_CouponType + { + + /// + /// 生效 + /// + [Description("满减优惠卷")] + 满减优惠卷=1, + /// + /// 生效 + /// + [Description("代金卷")] + 代金卷 = 2, + /// + /// 作废 + /// + [Description("无门槛优惠卷")] + 无门槛优惠卷 = 3 + } +}