diff --git a/ARW.Model/Dto/Api/Marketing/CouponManage/CustomerCoupons/CustomerCouponApiDto.cs b/ARW.Model/Dto/Api/Marketing/CouponManage/CustomerCoupons/CustomerCouponApiDto.cs new file mode 100644 index 0000000..d8a27d8 --- /dev/null +++ b/ARW.Model/Dto/Api/Marketing/CouponManage/CustomerCoupons/CustomerCouponApiDto.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using ARW.Model.Models.Business.Marketing.CouponManage.CustomerCoupons; + +namespace ARW.Model.Dto.Api.Marketing.CouponManage.CustomerCoupons +{ + + /// + /// 领券记录查询对象Api + /// + /// @author lwh + /// @date 2023-07-31 + /// + public class CustomerCouponQueryDtoApi : PagerInfo + { + [Required(ErrorMessage = "CustomerGuid不能为空")] + public long CustomerGuid{ get; set; } + + public int Status { get; set; } + } + + + /// + /// 领券记录详情输入对象Api + /// + /// @author lwh + /// @date 2023-07-31 + /// + public class CustomerCouponDtoApi + { + [Required(ErrorMessage = "CustomerCouponGuid不能为空")] + public long CustomerCouponGuid { get; set; } + } + +} diff --git a/ARW.Model/Dto/Business/Marketing/CouponManage/Coupons/CouponDto.cs b/ARW.Model/Dto/Business/Marketing/CouponManage/Coupons/CouponDto.cs index 20c1324..4748f59 100644 --- a/ARW.Model/Dto/Business/Marketing/CouponManage/Coupons/CouponDto.cs +++ b/ARW.Model/Dto/Business/Marketing/CouponManage/Coupons/CouponDto.cs @@ -26,6 +26,7 @@ namespace ARW.Model.Dto.Business.Marketing.CouponManage.Coupons [Required(ErrorMessage = "优惠劵介绍不能为空")] public string CouponDesc { get; set; } + public string CouponUseIntro { get; set; } [Required(ErrorMessage = "优惠劵类型不能为空")] public int CouponType { get; set; } diff --git a/ARW.Model/Models/Business/Marketing/CouponManage/Coupons/Coupon.cs b/ARW.Model/Models/Business/Marketing/CouponManage/Coupons/Coupon.cs index 744c8a1..b155e9e 100644 --- a/ARW.Model/Models/Business/Marketing/CouponManage/Coupons/Coupon.cs +++ b/ARW.Model/Models/Business/Marketing/CouponManage/Coupons/Coupon.cs @@ -51,6 +51,13 @@ namespace ARW.Model.Models.Business.Marketing.CouponManage.Coupons [SugarColumn(ColumnName = "coupon_desc")] public string CouponDesc { get; set; } + /// + /// 描述 :优惠劵使用须知 + /// 空值 : false + /// + [EpplusTableColumn(Header = "优惠劵使用须知")] + [SugarColumn(ColumnName = "coupon_use_intro")] + public string CouponUseIntro { get; set; } /// /// 描述 :优惠劵类型 @@ -76,7 +83,7 @@ namespace ARW.Model.Models.Business.Marketing.CouponManage.Coupons /// [EpplusTableColumn(Header = "折扣率")] [SugarColumn(ColumnName = "coupon_discount_rate")] - public byte CouponDiscountRate { get; set; } + public float CouponDiscountRate { get; set; } /// @@ -103,7 +110,7 @@ namespace ARW.Model.Models.Business.Marketing.CouponManage.Coupons /// [EpplusTableColumn(Header = "有效天数")] [SugarColumn(ColumnName = "coupon_effective_days")] - public int? CouponEffectiveDays { get; set; } + public int CouponEffectiveDays { get; set; } /// diff --git a/ARW.Model/Vo/Api/Marketing/CouponManage/CustomerCoupons/CustomerCouponApiVo.cs b/ARW.Model/Vo/Api/Marketing/CouponManage/CustomerCoupons/CustomerCouponApiVo.cs new file mode 100644 index 0000000..0489d8d --- /dev/null +++ b/ARW.Model/Vo/Api/Marketing/CouponManage/CustomerCoupons/CustomerCouponApiVo.cs @@ -0,0 +1,91 @@ +using Newtonsoft.Json; +using OfficeOpenXml.Attributes; +using SqlSugar; +using System; + +namespace ARW.Model.Vo.Api.Marketing.CouponManage.CustomerCoupons +{ + /// + /// 领券记录展示对象Api + /// + /// @author lwh + /// @date 2023-07-31 + /// + public class CustomerCouponVoApi + { + + /// + /// 描述 : CustomerCouponGuid + /// + [JsonConverter(typeof(ValueToStringConverter))] + [JsonIgnore] + public long CustomerCouponGuid { get; set; } + + + /// + /// 描述 : Key + /// + [JsonConverter(typeof(ValueToStringConverter))] + public long Key { get; set; } + + + /// + /// 描述 :优惠劵类型 + /// + public int Type { get; set; } + + /// + /// 描述 :优惠劵状态 + /// + public int Status { get; set; } + + /// + /// 描述 :折扣或者满减值 + /// + public string Value { get; set; } + + + /// + /// 描述 :描述 + /// + public string Desc { get; set; } + + + /// + /// 描述 :标题 + /// + public string Title { get; set; } + + /// + /// 描述 :订单底价,满n元 + /// + public decimal Base { get; set; } + + /// + /// 描述 :有效时间限制 + /// + public string TimeLimit { get; set; } + + [JsonIgnore] + public DateTime CreateTime { get; set; } + } + + + /// + /// 领券记录详情展示对象Api + /// + public class CustomerCouponApiDetailsVo + { + public int CustomerCouponId { get; set; } + [JsonConverter(typeof(ValueToStringConverter))] + public long CustomerCouponGuid { get; set; } + [JsonConverter(typeof(ValueToStringConverter))] + public long CouponGuid { get; set; } + [JsonConverter(typeof(ValueToStringConverter))] + public long CustomerGuid { get; set; } + public int CustomerCouponIsExpired { get; set; } + public int CustomerCouponIsUsed { get; set; } + + } + +} diff --git a/ARW.Model/Vo/Business/Marketing/CouponManage/Coupons/CouponVo.cs b/ARW.Model/Vo/Business/Marketing/CouponManage/Coupons/CouponVo.cs index f600575..c3905e6 100644 --- a/ARW.Model/Vo/Business/Marketing/CouponManage/Coupons/CouponVo.cs +++ b/ARW.Model/Vo/Business/Marketing/CouponManage/Coupons/CouponVo.cs @@ -42,6 +42,12 @@ namespace ARW.Model.Vo.Business.Marketing.CouponManage.Coupons [EpplusTableColumn(Header = "优惠劵介绍")] public string CouponDesc { get; set; } + /// + /// 描述 :优惠劵使用须知 + /// 空值 : false + /// + [EpplusTableColumn(Header = "优惠劵使用须知")] + public string CouponUseIntro { get; set; } /// /// 描述 :优惠劵类型 @@ -61,7 +67,7 @@ namespace ARW.Model.Vo.Business.Marketing.CouponManage.Coupons /// 描述 :折扣率 /// [EpplusIgnore] - public byte CouponDiscountRate { get; set; } + public float CouponDiscountRate { get; set; } /// diff --git a/ARW.Service/Api/BusinessService/Marketing/CouponManage/CustomerCoupons/CustomerCouponServiceApi.cs b/ARW.Service/Api/BusinessService/Marketing/CouponManage/CustomerCoupons/CustomerCouponServiceApi.cs new file mode 100644 index 0000000..258f8b8 --- /dev/null +++ b/ARW.Service/Api/BusinessService/Marketing/CouponManage/CustomerCoupons/CustomerCouponServiceApi.cs @@ -0,0 +1,141 @@ +using Infrastructure.Attribute; +using Microsoft.AspNetCore.Http; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ARW.Model; +using ARW.Repository; +using ARW.Repository.Business.Marketing.CouponManage.CustomerCoupons; +using ARW.Service.Api.IBusinessService.Marketing.CouponManage.CustomerCoupons; +using ARW.Model.Dto.Api.Marketing.CouponManage.CustomerCoupons; +using ARW.Model.Models.Business.Marketing.CouponManage.CustomerCoupons; +using ARW.Model.Vo.Api.Marketing.CouponManage.CustomerCoupons; +using ARW.Model.Models.Business.Marketing.CouponManage.Coupons; +using ARW.Repository.Business.Marketing.CouponManage.Coupons; +using ARW.Model.Vo.Business.Marketing.CouponManage.CustomerCoupons; + +namespace ARW.Service.Api.BusinessService.Marketing.CouponManage.CustomerCoupons +{ + /// + /// 领券记录接口实现类Api + /// + /// @author lwh + /// @date 2023-07-31 + /// + [AppService(ServiceType = typeof(ICustomerCouponServiceApi), ServiceLifetime = LifeTime.Transient)] + public class CustomerCouponServiceImplApi : BaseService, ICustomerCouponServiceApi + { + private readonly CustomerCouponRepository _CustomerCouponRepository; + private readonly CouponRepository _CouponRepository; + + public CustomerCouponServiceImplApi(CustomerCouponRepository CustomerCouponRepository, CouponRepository couponRepository) + { + this._CustomerCouponRepository = CustomerCouponRepository; + _CouponRepository = couponRepository; + } + + #region Api接口代码 + + + /// + /// 查询领券记录列表(Api) + /// + /// + /// + public async Task> GetCustomerCouponListApi(CustomerCouponQueryDtoApi parm) + { + //开始拼装查询条件d + var predicate = Expressionable.Create(); + + var query = _CustomerCouponRepository + .Queryable() + .LeftJoin((s, c) => s.CouponGuid == c.CouponGuid) + .Where(s => s.CustomerGuid == parm.CustomerGuid) + .WhereIF(parm.Status == 1, s => s.CustomerCouponIsUsed == 1 && s.CustomerCouponIsExpired == 1) + .WhereIF(parm.Status == 2, s => s.CustomerCouponIsUsed == 2) + .WhereIF(parm.Status == 3, s => s.CustomerCouponIsExpired == 2) + .OrderBy(s => s.Create_time, OrderByType.Desc) + .Select((s, c) => new CustomerCouponVoApi + { + CustomerCouponGuid = s.CustomerCouponGuid, + Key = c.CouponGuid, + Type = c.CouponType, + Value = c.CouponDeductionMoney != 0 ? c.CouponDeductionMoney.ToString() : c.CouponDiscountRate.ToString(), + Desc = c.CouponDesc, + Title = c.CouponName, + Base = c.CouponMinConsumeMoney, + CreateTime = s.Create_time + }); + + + var list = await query.ToListAsync(); + + + foreach (var item in list) + { + // 处理有效日期 + var coupon = await _CouponRepository.GetFirstAsync(s => s.CouponGuid == item.Key); + if (coupon.CouponExpireType == 1) + { + var firstTime = item.CreateTime.ToString("yyyy.MM.dd"); + var lastTime = item.CreateTime.AddDays(coupon.CouponEffectiveDays).ToString("yyyy.MM.dd"); + item.TimeLimit = firstTime + "-" + lastTime; + } + else + { + var firstTime = coupon.CouponFixedStartTime.ToString("yyyy.MM.dd"); + var lastTime = coupon.CouponFixedEndTime.ToString("yyyy.MM.dd"); + item.TimeLimit = firstTime + "-" + lastTime; + } + + // 处理优惠券状态 + var customerCoupon = await _CustomerCouponRepository.GetFirstAsync(s => s.CustomerCouponGuid == item.CustomerCouponGuid); + + // 可使用 + if (customerCoupon.CustomerCouponIsUsed == 1 && customerCoupon.CustomerCouponIsExpired == 1) + item.Status = 1; + // 已使用 + if (customerCoupon.CustomerCouponIsUsed == 2) + item.Status = 2; + // 已过期 + if (customerCoupon.CustomerCouponIsExpired == 2) + item.Status = 3; + + } + + return list; + } + + /// + /// 查询领券记录详情(Api) + /// + /// + /// + public async Task GetCustomerCouponDetails(CustomerCouponDtoApi parm) + { + + var query = _CustomerCouponRepository + .Queryable() + .Where(s => s.CustomerCouponGuid == parm.CustomerCouponGuid) + .Select(s => new CustomerCouponApiDetailsVo + { + CustomerCouponId = s.CustomerCouponId, + CustomerCouponGuid = s.CustomerCouponGuid, + CouponGuid = s.CouponGuid, + CustomerGuid = s.CustomerGuid, + CustomerCouponIsExpired = s.CustomerCouponIsExpired, + CustomerCouponIsUsed = s.CustomerCouponIsUsed, + }).Take(1); + + + return await query.ToJsonAsync(); + } + + + #endregion + + } +} diff --git a/ARW.Service/Api/IBusinessService/Marketing/CouponManage/CustomerCoupons/ICustomerCouponServiceApi.cs b/ARW.Service/Api/IBusinessService/Marketing/CouponManage/CustomerCoupons/ICustomerCouponServiceApi.cs new file mode 100644 index 0000000..1bc9e09 --- /dev/null +++ b/ARW.Service/Api/IBusinessService/Marketing/CouponManage/CustomerCoupons/ICustomerCouponServiceApi.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ARW.Model; +using ARW.Model.Dto.Api.Marketing.CouponManage.CustomerCoupons; +using ARW.Model.Models.Business.Marketing.CouponManage.CustomerCoupons; +using ARW.Model.Vo.Api.Marketing.CouponManage.CustomerCoupons; + +namespace ARW.Service.Api.IBusinessService.Marketing.CouponManage.CustomerCoupons +{ + /// + /// 领券记录接口类Api + /// + /// @author lwh + /// @date 2023-07-31 + /// + public interface ICustomerCouponServiceApi : IBaseService + { + /// + /// 获取领券记录分页列表(Api) + /// + /// + /// + Task> GetCustomerCouponListApi(CustomerCouponQueryDtoApi parm); + + /// + /// 获取领券记录详情(Api) + /// + /// + /// + Task GetCustomerCouponDetails(CustomerCouponDtoApi parm); + + } +} diff --git a/ARW.Service/Business/BusinessService/Marketing/CouponManage/Coupons/CouponService.cs b/ARW.Service/Business/BusinessService/Marketing/CouponManage/Coupons/CouponService.cs index d92397d..f1129b3 100644 --- a/ARW.Service/Business/BusinessService/Marketing/CouponManage/Coupons/CouponService.cs +++ b/ARW.Service/Business/BusinessService/Marketing/CouponManage/Coupons/CouponService.cs @@ -60,6 +60,7 @@ namespace ARW.Service.Business.BusinessService.Marketing.CouponManage.Coupons CouponName = s.CouponName, CouponDesc = s.CouponDesc, CouponType = s.CouponType, + CouponUseIntro = s.CouponUseIntro, CouponDeductionMoney = s.CouponDeductionMoney, CouponDiscountRate = s.CouponDiscountRate, CouponMinConsumeMoney = s.CouponMinConsumeMoney, diff --git a/ARW.WebApi/Controllers/Api/Marketing/CouponManage/CustomerCoupons/CustomerCouponApiController.cs b/ARW.WebApi/Controllers/Api/Marketing/CouponManage/CustomerCoupons/CustomerCouponApiController.cs new file mode 100644 index 0000000..0f8422a --- /dev/null +++ b/ARW.WebApi/Controllers/Api/Marketing/CouponManage/CustomerCoupons/CustomerCouponApiController.cs @@ -0,0 +1,84 @@ +using Infrastructure; +using Infrastructure.Attribute; +using Infrastructure.Enums; +using Infrastructure.Model; +using Mapster; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using ARW.Admin.WebApi.Extensions; +using ARW.Admin.WebApi.Filters; +using ARW.Common; +using ARW.Admin.WebApi.Controllers; +using ARW.Model.Dto.Api.Marketing.CouponManage.CustomerCoupons; +using ARW.Service.Api.IBusinessService.Marketing.CouponManage.CustomerCoupons; +using ARW.Model.Models.Business.Marketing.CouponManage.CustomerCoupons; +using ARW.Model.Vo.Api.Marketing.CouponManage.CustomerCoupons; +using Microsoft.AspNetCore.Authorization; +using Geocoding; +using ARW.Admin.WebApi.Framework; + +namespace ARW.WebApi.Controllers.Api.Marketing.CouponManage.CustomerCoupons +{ + /// + /// 领券记录控制器Api + /// + /// @author lwh + /// @date 2023-07-31 + /// + [Verify] + [Route("api/[controller]")] + public class CustomerCouponApiController : BaseController + { + private readonly ICustomerCouponServiceApi _CustomerCouponServiceApi; + + /// + /// 依赖注入 + /// + /// 领券记录领券记录Api服务 + public CustomerCouponApiController(ICustomerCouponServiceApi CustomerCouponServiceApi) + { + _CustomerCouponServiceApi = CustomerCouponServiceApi; + } + + + /// + /// 获取领券记录列表(Api) + /// + /// 查询参数 + /// + [HttpGet("getCustomerCouponList")] + public async Task GetCustomerCouponListApi([FromQuery] CustomerCouponQueryDtoApi parm) + { + var user = JwtUtil.GetLoginUser(App.HttpContext); + parm.CustomerGuid = user.UserId; + var res = await _CustomerCouponServiceApi.GetCustomerCouponListApi(parm); + return SUCCESS(res); + } + + /// + /// 获取CustomerCoupon详情(Api) + /// + /// 查询参数 + /// + [HttpGet("getCustomerCouponDetails")] + public async Task GetCustomerCouponDetails([FromQuery] CustomerCouponDtoApi parm) + { + //if (parm == null) throw new CustomException("参数错误!"); + + var res = await _CustomerCouponServiceApi.GetCustomerCouponDetails(parm); + + if (res != "[]") + { + res = res.Remove(0, 1); + res = res.Substring(0, res.Length - 1); + var data = res.FromJSON(); + return SUCCESS(data); + } + else + { + return SUCCESS(res); + } + } + + } +}