faet 添加优惠券列表接口
This commit is contained in:
parent
e56330d530
commit
e9ee2fa7df
@ -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
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 领券记录查询对象Api
|
||||
///
|
||||
/// @author lwh
|
||||
/// @date 2023-07-31
|
||||
/// </summary>
|
||||
public class CustomerCouponQueryDtoApi : PagerInfo
|
||||
{
|
||||
[Required(ErrorMessage = "CustomerGuid不能为空")]
|
||||
public long CustomerGuid{ get; set; }
|
||||
|
||||
public int Status { get; set; }
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 领券记录详情输入对象Api
|
||||
///
|
||||
/// @author lwh
|
||||
/// @date 2023-07-31
|
||||
/// </summary>
|
||||
public class CustomerCouponDtoApi
|
||||
{
|
||||
[Required(ErrorMessage = "CustomerCouponGuid不能为空")]
|
||||
public long CustomerCouponGuid { get; set; }
|
||||
}
|
||||
|
||||
}
|
@ -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; }
|
||||
|
@ -51,6 +51,13 @@ namespace ARW.Model.Models.Business.Marketing.CouponManage.Coupons
|
||||
[SugarColumn(ColumnName = "coupon_desc")]
|
||||
public string CouponDesc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :优惠劵使用须知
|
||||
/// 空值 : false
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "优惠劵使用须知")]
|
||||
[SugarColumn(ColumnName = "coupon_use_intro")]
|
||||
public string CouponUseIntro { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :优惠劵类型
|
||||
@ -76,7 +83,7 @@ namespace ARW.Model.Models.Business.Marketing.CouponManage.Coupons
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "折扣率")]
|
||||
[SugarColumn(ColumnName = "coupon_discount_rate")]
|
||||
public byte CouponDiscountRate { get; set; }
|
||||
public float CouponDiscountRate { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
@ -103,7 +110,7 @@ namespace ARW.Model.Models.Business.Marketing.CouponManage.Coupons
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "有效天数")]
|
||||
[SugarColumn(ColumnName = "coupon_effective_days")]
|
||||
public int? CouponEffectiveDays { get; set; }
|
||||
public int CouponEffectiveDays { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
@ -0,0 +1,91 @@
|
||||
using Newtonsoft.Json;
|
||||
using OfficeOpenXml.Attributes;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
|
||||
namespace ARW.Model.Vo.Api.Marketing.CouponManage.CustomerCoupons
|
||||
{
|
||||
/// <summary>
|
||||
/// 领券记录展示对象Api
|
||||
///
|
||||
/// @author lwh
|
||||
/// @date 2023-07-31
|
||||
/// </summary>
|
||||
public class CustomerCouponVoApi
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 描述 : CustomerCouponGuid
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
[JsonIgnore]
|
||||
public long CustomerCouponGuid { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 : Key
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
public long Key { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :优惠劵类型
|
||||
/// </summary>
|
||||
public int Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :优惠劵状态
|
||||
/// </summary>
|
||||
public int Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :折扣或者满减值
|
||||
/// </summary>
|
||||
public string Value { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :描述
|
||||
/// </summary>
|
||||
public string Desc { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :标题
|
||||
/// </summary>
|
||||
public string Title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :订单底价,满n元
|
||||
/// </summary>
|
||||
public decimal Base { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :有效时间限制
|
||||
/// </summary>
|
||||
public string TimeLimit { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public DateTime CreateTime { get; set; }
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 领券记录详情展示对象Api
|
||||
/// </summary>
|
||||
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; }
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -42,6 +42,12 @@ namespace ARW.Model.Vo.Business.Marketing.CouponManage.Coupons
|
||||
[EpplusTableColumn(Header = "优惠劵介绍")]
|
||||
public string CouponDesc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :优惠劵使用须知
|
||||
/// 空值 : false
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "优惠劵使用须知")]
|
||||
public string CouponUseIntro { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :优惠劵类型
|
||||
@ -61,7 +67,7 @@ namespace ARW.Model.Vo.Business.Marketing.CouponManage.Coupons
|
||||
/// 描述 :折扣率
|
||||
/// </summary>
|
||||
[EpplusIgnore]
|
||||
public byte CouponDiscountRate { get; set; }
|
||||
public float CouponDiscountRate { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// 领券记录接口实现类Api
|
||||
///
|
||||
/// @author lwh
|
||||
/// @date 2023-07-31
|
||||
/// </summary>
|
||||
[AppService(ServiceType = typeof(ICustomerCouponServiceApi), ServiceLifetime = LifeTime.Transient)]
|
||||
public class CustomerCouponServiceImplApi : BaseService<CustomerCoupon>, ICustomerCouponServiceApi
|
||||
{
|
||||
private readonly CustomerCouponRepository _CustomerCouponRepository;
|
||||
private readonly CouponRepository _CouponRepository;
|
||||
|
||||
public CustomerCouponServiceImplApi(CustomerCouponRepository CustomerCouponRepository, CouponRepository couponRepository)
|
||||
{
|
||||
this._CustomerCouponRepository = CustomerCouponRepository;
|
||||
_CouponRepository = couponRepository;
|
||||
}
|
||||
|
||||
#region Api接口代码
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 查询领券记录列表(Api)
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<CustomerCouponVoApi>> GetCustomerCouponListApi(CustomerCouponQueryDtoApi parm)
|
||||
{
|
||||
//开始拼装查询条件d
|
||||
var predicate = Expressionable.Create<CustomerCoupon>();
|
||||
|
||||
var query = _CustomerCouponRepository
|
||||
.Queryable()
|
||||
.LeftJoin<Coupon>((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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询领券记录详情(Api)
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<string> 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
|
||||
|
||||
}
|
||||
}
|
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// 领券记录接口类Api
|
||||
///
|
||||
/// @author lwh
|
||||
/// @date 2023-07-31
|
||||
/// </summary>
|
||||
public interface ICustomerCouponServiceApi : IBaseService<CustomerCoupon>
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取领券记录分页列表(Api)
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<CustomerCouponVoApi>> GetCustomerCouponListApi(CustomerCouponQueryDtoApi parm);
|
||||
|
||||
/// <summary>
|
||||
/// 获取领券记录详情(Api)
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
Task<string> GetCustomerCouponDetails(CustomerCouponDtoApi parm);
|
||||
|
||||
}
|
||||
}
|
@ -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,
|
||||
|
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// 领券记录控制器Api
|
||||
///
|
||||
/// @author lwh
|
||||
/// @date 2023-07-31
|
||||
/// </summary>
|
||||
[Verify]
|
||||
[Route("api/[controller]")]
|
||||
public class CustomerCouponApiController : BaseController
|
||||
{
|
||||
private readonly ICustomerCouponServiceApi _CustomerCouponServiceApi;
|
||||
|
||||
/// <summary>
|
||||
/// 依赖注入
|
||||
/// </summary>
|
||||
/// <param name="CustomerCouponServiceApi">领券记录领券记录Api服务</param>
|
||||
public CustomerCouponApiController(ICustomerCouponServiceApi CustomerCouponServiceApi)
|
||||
{
|
||||
_CustomerCouponServiceApi = CustomerCouponServiceApi;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取领券记录列表(Api)
|
||||
/// </summary>
|
||||
/// <param name="parm">查询参数</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("getCustomerCouponList")]
|
||||
public async Task<IActionResult> GetCustomerCouponListApi([FromQuery] CustomerCouponQueryDtoApi parm)
|
||||
{
|
||||
var user = JwtUtil.GetLoginUser(App.HttpContext);
|
||||
parm.CustomerGuid = user.UserId;
|
||||
var res = await _CustomerCouponServiceApi.GetCustomerCouponListApi(parm);
|
||||
return SUCCESS(res);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取CustomerCoupon详情(Api)
|
||||
/// </summary>
|
||||
/// <param name="parm">查询参数</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("getCustomerCouponDetails")]
|
||||
public async Task<IActionResult> 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<CustomerCouponApiDetailsVo>();
|
||||
return SUCCESS(data);
|
||||
}
|
||||
else
|
||||
{
|
||||
return SUCCESS(res);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user