From 064b9fea0ad3dbd8fbd4843fa4ac5e890db8f56e Mon Sep 17 00:00:00 2001 From: lwh <2679599887@qq.com> Date: Tue, 1 Aug 2023 17:21:36 +0800 Subject: [PATCH] =?UTF-8?q?fixed=20=E5=AE=8C=E5=96=84=E4=BC=98=E6=83=A0?= =?UTF-8?q?=E5=88=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CustomerCoupons/CustomerCouponApiDto.cs | 2 +- .../Marketing/CouponManage/Coupons/Coupon.cs | 2 +- .../CustomerCoupons/CustomerCouponApiVo.cs | 75 ++++++++++++++--- .../CustomerCouponServiceApi.cs | 83 +++++++++++++++---- .../CustomerCouponApiController.cs | 2 - 5 files changed, 134 insertions(+), 30 deletions(-) diff --git a/ARW.Model/Dto/Api/Marketing/CouponManage/CustomerCoupons/CustomerCouponApiDto.cs b/ARW.Model/Dto/Api/Marketing/CouponManage/CustomerCoupons/CustomerCouponApiDto.cs index d8a27d8..2ef54e0 100644 --- a/ARW.Model/Dto/Api/Marketing/CouponManage/CustomerCoupons/CustomerCouponApiDto.cs +++ b/ARW.Model/Dto/Api/Marketing/CouponManage/CustomerCoupons/CustomerCouponApiDto.cs @@ -30,7 +30,7 @@ namespace ARW.Model.Dto.Api.Marketing.CouponManage.CustomerCoupons public class CustomerCouponDtoApi { [Required(ErrorMessage = "CustomerCouponGuid不能为空")] - public long CustomerCouponGuid { get; set; } + public long CustomerCouponId { 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 b155e9e..2c09609 100644 --- a/ARW.Model/Models/Business/Marketing/CouponManage/Coupons/Coupon.cs +++ b/ARW.Model/Models/Business/Marketing/CouponManage/Coupons/Coupon.cs @@ -137,7 +137,7 @@ namespace ARW.Model.Models.Business.Marketing.CouponManage.Coupons /// [EpplusTableColumn(Header = "适用范围")] [SugarColumn(ColumnName = "coupon_applicable_scope")] - public int? CouponApplicableScope { get; set; } + public int CouponApplicableScope { get; set; } /// diff --git a/ARW.Model/Vo/Api/Marketing/CouponManage/CustomerCoupons/CustomerCouponApiVo.cs b/ARW.Model/Vo/Api/Marketing/CouponManage/CustomerCoupons/CustomerCouponApiVo.cs index 0489d8d..27056bc 100644 --- a/ARW.Model/Vo/Api/Marketing/CouponManage/CustomerCoupons/CustomerCouponApiVo.cs +++ b/ARW.Model/Vo/Api/Marketing/CouponManage/CustomerCoupons/CustomerCouponApiVo.cs @@ -15,18 +15,17 @@ namespace ARW.Model.Vo.Api.Marketing.CouponManage.CustomerCoupons { /// - /// 描述 : CustomerCouponGuid + /// 描述 : CouponGuid /// [JsonConverter(typeof(ValueToStringConverter))] [JsonIgnore] - public long CustomerCouponGuid { get; set; } + public long CouponGuid { get; set; } /// /// 描述 : Key /// - [JsonConverter(typeof(ValueToStringConverter))] - public long Key { get; set; } + public int Key { get; set; } /// @@ -76,16 +75,68 @@ namespace ARW.Model.Vo.Api.Marketing.CouponManage.CustomerCoupons /// public class CustomerCouponApiDetailsVo { - public int CustomerCouponId { get; set; } - [JsonConverter(typeof(ValueToStringConverter))] - public long CustomerCouponGuid { get; set; } - [JsonConverter(typeof(ValueToStringConverter))] + /// + /// 描述 : CouponGuid + /// + [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; } + + /// + /// 描述 : Key + /// + public int 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; } + + /// + /// 适用范围 + /// + public string StoreAdapt { get; set; } + + /// + /// 使用须知 + /// + public string UseNotes { get; set; } } } diff --git a/ARW.Service/Api/BusinessService/Marketing/CouponManage/CustomerCoupons/CustomerCouponServiceApi.cs b/ARW.Service/Api/BusinessService/Marketing/CouponManage/CustomerCoupons/CustomerCouponServiceApi.cs index 258f8b8..18196e1 100644 --- a/ARW.Service/Api/BusinessService/Marketing/CouponManage/CustomerCoupons/CustomerCouponServiceApi.cs +++ b/ARW.Service/Api/BusinessService/Marketing/CouponManage/CustomerCoupons/CustomerCouponServiceApi.cs @@ -16,6 +16,10 @@ 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; +using Senparc.Weixin.WxOpen.AdvancedAPIs.WxApp.WxAppJson; +using ARW.Model.Vo.Api.GoodsManager.Goodss; +using Newtonsoft.Json; +using Senparc.CO2NET.Extensions; namespace ARW.Service.Api.BusinessService.Marketing.CouponManage.CustomerCoupons { @@ -53,15 +57,15 @@ namespace ARW.Service.Api.BusinessService.Marketing.CouponManage.CustomerCoupons var query = _CustomerCouponRepository .Queryable() .LeftJoin((s, c) => s.CouponGuid == c.CouponGuid) - .Where(s => s.CustomerGuid == parm.CustomerGuid) + .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, + CouponGuid = c.CouponGuid, + Key = s.CustomerCouponId, Type = c.CouponType, Value = c.CouponDeductionMoney != 0 ? c.CouponDeductionMoney.ToString() : c.CouponDiscountRate.ToString(), Desc = c.CouponDesc, @@ -77,7 +81,7 @@ namespace ARW.Service.Api.BusinessService.Marketing.CouponManage.CustomerCoupons foreach (var item in list) { // 处理有效日期 - var coupon = await _CouponRepository.GetFirstAsync(s => s.CouponGuid == item.Key); + var coupon = await _CouponRepository.GetFirstAsync(s => s.CouponGuid == item.CouponGuid); if (coupon.CouponExpireType == 1) { var firstTime = item.CreateTime.ToString("yyyy.MM.dd"); @@ -92,7 +96,7 @@ namespace ARW.Service.Api.BusinessService.Marketing.CouponManage.CustomerCoupons } // 处理优惠券状态 - var customerCoupon = await _CustomerCouponRepository.GetFirstAsync(s => s.CustomerCouponGuid == item.CustomerCouponGuid); + var customerCoupon = await _CustomerCouponRepository.GetFirstAsync(s => s.CustomerCouponId == item.Key); // 可使用 if (customerCoupon.CustomerCouponIsUsed == 1 && customerCoupon.CustomerCouponIsExpired == 1) @@ -119,19 +123,70 @@ namespace ARW.Service.Api.BusinessService.Marketing.CouponManage.CustomerCoupons var query = _CustomerCouponRepository .Queryable() - .Where(s => s.CustomerCouponGuid == parm.CustomerCouponGuid) - .Select(s => new CustomerCouponApiDetailsVo + .LeftJoin((s, c) => s.CouponGuid == c.CouponGuid) + .Where(s => s.CustomerCouponId == parm.CustomerCouponId) + .Select((s, c) => new CustomerCouponApiDetailsVo { - CustomerCouponId = s.CustomerCouponId, - CustomerCouponGuid = s.CustomerCouponGuid, - CouponGuid = s.CouponGuid, - CustomerGuid = s.CustomerGuid, - CustomerCouponIsExpired = s.CustomerCouponIsExpired, - CustomerCouponIsUsed = s.CustomerCouponIsUsed, + CouponGuid = c.CouponGuid, + Key = s.CustomerCouponId, + 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, + UseNotes = c.CouponUseIntro, }).Take(1); - return await query.ToJsonAsync(); + var json = await query.ToJsonAsync(); + + if (json != "[]") + { + json = json.Remove(0, 1); + json = json.Substring(0, json.Length - 1); + var data = JsonConvert.DeserializeObject(json); + + // 处理有效日期 + var coupon = await _CouponRepository.GetFirstAsync(s => s.CouponGuid == data.CouponGuid); + + // 使用范围 + if(coupon.CouponApplicableScope == 1) + data.StoreAdapt = "全部商品"; + if (coupon.CouponApplicableScope == 2) + data.StoreAdapt = "指定商品"; + + if (coupon.CouponExpireType == 1) + { + var firstTime = data.CreateTime.ToString("yyyy.MM.dd"); + var lastTime = data.CreateTime.AddDays(coupon.CouponEffectiveDays).ToString("yyyy.MM.dd"); + data.TimeLimit = firstTime + "-" + lastTime; + } + else + { + var firstTime = coupon.CouponFixedStartTime.ToString("yyyy.MM.dd"); + var lastTime = coupon.CouponFixedEndTime.ToString("yyyy.MM.dd"); + data.TimeLimit = firstTime + "-" + lastTime; + } + + // 处理优惠券状态 + var customerCoupon = await _CustomerCouponRepository.GetFirstAsync(s => s.CustomerCouponId == data.Key); + + // 可使用 + if (customerCoupon.CustomerCouponIsUsed == 1 && customerCoupon.CustomerCouponIsExpired == 1) + data.Status = 1; + // 已使用 + if (customerCoupon.CustomerCouponIsUsed == 2) + data.Status = 2; + // 已过期 + if (customerCoupon.CustomerCouponIsExpired == 2) + data.Status = 3; + + json = data.ToJson(); + + } + return json; + //return await query.ToJsonAsync(); } diff --git a/ARW.WebApi/Controllers/Api/Marketing/CouponManage/CustomerCoupons/CustomerCouponApiController.cs b/ARW.WebApi/Controllers/Api/Marketing/CouponManage/CustomerCoupons/CustomerCouponApiController.cs index 0f8422a..7a2c24f 100644 --- a/ARW.WebApi/Controllers/Api/Marketing/CouponManage/CustomerCoupons/CustomerCouponApiController.cs +++ b/ARW.WebApi/Controllers/Api/Marketing/CouponManage/CustomerCoupons/CustomerCouponApiController.cs @@ -69,8 +69,6 @@ namespace ARW.WebApi.Controllers.Api.Marketing.CouponManage.CustomerCoupons if (res != "[]") { - res = res.Remove(0, 1); - res = res.Substring(0, res.Length - 1); var data = res.FromJSON(); return SUCCESS(data); }