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