feat 初始化优惠券,添加多选商品的弹窗和接口
This commit is contained in:
parent
ad5b364567
commit
d8188a9ce1
@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using ARW.Model.Models.Business.Marketing.CouponManage.Coupons;
|
||||
|
||||
namespace ARW.Model.Dto.Business.Marketing.CouponManage.Coupons
|
||||
{
|
||||
/// <summary>
|
||||
/// 优惠券输入对象
|
||||
///
|
||||
/// @author lwh
|
||||
/// @date 2023-07-24
|
||||
/// </summary>
|
||||
public class CouponDto
|
||||
{
|
||||
|
||||
public int CouponId { get; set; }
|
||||
|
||||
public long CouponGuid { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "优惠劵名称不能为空")]
|
||||
public string CouponName { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "优惠劵类型不能为空")]
|
||||
public int CouponType { get; set; }
|
||||
|
||||
public decimal CouponDeductionMoney { get; set; }
|
||||
|
||||
public byte CouponDiscountRate { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "最低消费金额不能为空")]
|
||||
public decimal CouponMinConsumeMoney { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "到期类型不能为空")]
|
||||
public int CouponExpireType { get; set; }
|
||||
|
||||
public int? CouponEffectiveDays { get; set; }
|
||||
|
||||
public DateTime? CouponFixedStartTime { get; set; }
|
||||
|
||||
public DateTime? CouponFixedEndTime { get; set; }
|
||||
|
||||
public int? CouponApplicableScope { get; set; }
|
||||
|
||||
|
||||
[Required(ErrorMessage = "发送数量(-1不限制)不能为空")]
|
||||
public int CouponSendNumber { get; set; }
|
||||
|
||||
public int? CouponGetNumber { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "显示状态不能为空")]
|
||||
public int CouponDisplayStatus { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "排序不能为空")]
|
||||
public int CouponSort { get; set; }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 优惠券查询对象
|
||||
///
|
||||
/// @author lwh
|
||||
/// @date 2023-07-24
|
||||
/// </summary>
|
||||
public class CouponQueryDto : PagerInfo
|
||||
{
|
||||
|
||||
public string CouponName { get; set; }
|
||||
|
||||
public int? CouponType { get; set; }
|
||||
|
||||
public int? CouponExpireType { get; set; }
|
||||
|
||||
public int? CouponApplicableScope { get; set; }
|
||||
|
||||
public int? CouponDisplayStatus { get; set; }
|
||||
|
||||
public string ids { get; set; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,178 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using SqlSugar;
|
||||
using OfficeOpenXml.Attributes;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace ARW.Model.Models.Business.Marketing.CouponManage.Coupons
|
||||
{
|
||||
/// <summary>
|
||||
/// 优惠券,数据实体对象
|
||||
///
|
||||
/// @author lwh
|
||||
/// @date 2023-07-24
|
||||
/// </summary>
|
||||
[SugarTable("tb_coupon")]
|
||||
public class Coupon : BusinessBase
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :
|
||||
/// 空值 : false
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "CouponId")]
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "coupon_id")]
|
||||
public int CouponId { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :
|
||||
/// 空值 : false
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "CouponGuid")]
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = false, ColumnName = "coupon_guid")]
|
||||
public long CouponGuid { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :优惠劵名称
|
||||
/// 空值 : false
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "优惠劵名称")]
|
||||
[SugarColumn(ColumnName = "coupon_name")]
|
||||
public string CouponName { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :优惠劵类型
|
||||
/// 空值 : false
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "优惠劵类型")]
|
||||
[SugarColumn(ColumnName = "coupon_type")]
|
||||
public int CouponType { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :减免金额
|
||||
/// 空值 : true
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "减免金额")]
|
||||
[SugarColumn(ColumnName = "coupon_deduction_money")]
|
||||
public decimal CouponDeductionMoney { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :折扣率
|
||||
/// 空值 : true
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "折扣率")]
|
||||
[SugarColumn(ColumnName = "coupon_discount_rate")]
|
||||
public byte CouponDiscountRate { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :最低消费金额
|
||||
/// 空值 : false
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "最低消费金额")]
|
||||
[SugarColumn(ColumnName = "coupon_min_consume_money")]
|
||||
public decimal CouponMinConsumeMoney { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :到期类型
|
||||
/// 空值 : false
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "到期类型")]
|
||||
[SugarColumn(ColumnName = "coupon_expire_type")]
|
||||
public int CouponExpireType { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :有效天数
|
||||
/// 空值 : true
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "有效天数")]
|
||||
[SugarColumn(ColumnName = "coupon_effective_days")]
|
||||
public int? CouponEffectiveDays { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :固定时间-开始时间
|
||||
/// 空值 : true
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "固定时间-开始时间", NumberFormat = "yyyy-MM-dd HH:mm:ss")]
|
||||
[SugarColumn(ColumnName = "coupon_fixed_start_time")]
|
||||
public DateTime? CouponFixedStartTime { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :固定时间-结束时间
|
||||
/// 空值 : true
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "固定时间-结束时间", NumberFormat = "yyyy-MM-dd HH:mm:ss")]
|
||||
[SugarColumn(ColumnName = "coupon_fixed_end_time")]
|
||||
public DateTime? CouponFixedEndTime { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :适用范围
|
||||
/// 空值 : true
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "适用范围")]
|
||||
[SugarColumn(ColumnName = "coupon_applicable_scope")]
|
||||
public int? CouponApplicableScope { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :适用范围配置(json)
|
||||
/// 空值 : true
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "适用范围配置(json)")]
|
||||
[SugarColumn(ColumnName = "coupon_applicable_scope_config")]
|
||||
public string CouponApplicableScopeConfig { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :发送数量(-1不限制)
|
||||
/// 空值 : false
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "发送数量(-1不限制)")]
|
||||
[SugarColumn(ColumnName = "coupon_send_number")]
|
||||
public int CouponSendNumber { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :已领取数量
|
||||
/// 空值 : true
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "已领取数量")]
|
||||
[SugarColumn(ColumnName = "coupon_get_number")]
|
||||
public int? CouponGetNumber { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :显示状态
|
||||
/// 空值 : false
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "显示状态")]
|
||||
[SugarColumn(ColumnName = "coupon_display_status")]
|
||||
public int CouponDisplayStatus { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :排序
|
||||
/// 空值 : false
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "排序")]
|
||||
[SugarColumn(ColumnName = "coupon_sort")]
|
||||
public int CouponSort { get; set; }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
80
ARW.Model/Vo/Business/GoodsManager/Goodss/AllGoodsVo.cs
Normal file
80
ARW.Model/Vo/Business/GoodsManager/Goodss/AllGoodsVo.cs
Normal file
@ -0,0 +1,80 @@
|
||||
using Newtonsoft.Json;
|
||||
using OfficeOpenXml.Attributes;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ARW.Model.Vo.Business.GoodsManager.Goodss
|
||||
{
|
||||
/// <summary>
|
||||
/// 全部商品展示对象
|
||||
///
|
||||
/// @author lwh
|
||||
/// @date 2023-07-24
|
||||
/// </summary>
|
||||
public class AllGoodsVo
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :
|
||||
/// </summary>
|
||||
[EpplusIgnore]
|
||||
public int GoodsId { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
[EpplusIgnore]
|
||||
public long GoodsGuid { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :名称
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "商品名称")]
|
||||
public string GoodsName { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :图片
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "商品图片")]
|
||||
public string GoodsPicture { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :价格(最低)
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "商品价格")]
|
||||
public decimal GoodsPriceLowest { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :划线价格(最低)
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "划线价格")]
|
||||
public decimal GoodsDashedPriceLowest { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :上下架状态(1上架 2下架)
|
||||
/// </summary>
|
||||
[EpplusIgnore]
|
||||
public int GoodsShelfStatus { get; set; }
|
||||
|
||||
|
||||
[EpplusTableColumn(Header = "状态")]
|
||||
public string GoodsShelfStatusName { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :排序
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "排序")]
|
||||
public int GoodsSort { get; set; }
|
||||
|
||||
}
|
||||
}
|
126
ARW.Model/Vo/Business/Marketing/CouponManage/Coupons/CouponVo.cs
Normal file
126
ARW.Model/Vo/Business/Marketing/CouponManage/Coupons/CouponVo.cs
Normal file
@ -0,0 +1,126 @@
|
||||
using Newtonsoft.Json;
|
||||
using OfficeOpenXml.Attributes;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
|
||||
namespace ARW.Model.Vo.Business.Marketing.CouponManage.Coupons
|
||||
{
|
||||
/// <summary>
|
||||
/// 优惠券展示对象
|
||||
///
|
||||
/// @author lwh
|
||||
/// @date 2023-07-24
|
||||
/// </summary>
|
||||
public class CouponVo
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :
|
||||
/// </summary>
|
||||
[EpplusIgnore]
|
||||
public int CouponId { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
[EpplusIgnore]
|
||||
public long CouponGuid { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :优惠劵名称
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "优惠劵名称")]
|
||||
public string CouponName { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :优惠劵类型
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "优惠劵类型")]
|
||||
public int CouponType { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :减免金额
|
||||
/// </summary>
|
||||
[EpplusIgnore]
|
||||
public decimal CouponDeductionMoney { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :折扣率
|
||||
/// </summary>
|
||||
[EpplusIgnore]
|
||||
public byte CouponDiscountRate { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :最低消费金额
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "最低消费金额")]
|
||||
public decimal CouponMinConsumeMoney { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :到期类型
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "到期类型")]
|
||||
public int CouponExpireType { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :有效天数
|
||||
/// </summary>
|
||||
[EpplusIgnore]
|
||||
public int? CouponEffectiveDays { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :固定时间-开始时间
|
||||
/// </summary>
|
||||
[EpplusIgnore]
|
||||
public DateTime? CouponFixedStartTime { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :固定时间-结束时间
|
||||
/// </summary>
|
||||
[EpplusIgnore]
|
||||
public DateTime? CouponFixedEndTime { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :适用范围
|
||||
/// </summary>
|
||||
[EpplusIgnore]
|
||||
public int? CouponApplicableScope { get; set; }
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :发送数量(-1不限制)
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "发送数量(-1不限制)")]
|
||||
public int CouponSendNumber { get; set; }
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :显示状态
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "显示状态")]
|
||||
public int CouponDisplayStatus { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :排序
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "排序")]
|
||||
public int CouponSort { get; set; }
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using Infrastructure.Attribute;
|
||||
using ARW.Repository.System;
|
||||
using ARW.Model.Models.Business.Marketing.CouponManage.Coupons;
|
||||
|
||||
namespace ARW.Repository.Business.Marketing.CouponManage.Coupons
|
||||
{
|
||||
/// <summary>
|
||||
/// 优惠券仓储
|
||||
///
|
||||
/// @author lwh
|
||||
/// @date 2023-07-24
|
||||
/// </summary>
|
||||
[AppService(ServiceLifetime = LifeTime.Transient)]
|
||||
public class CouponRepository : BaseRepository<Coupon>
|
||||
{
|
||||
#region 业务逻辑代码
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -191,6 +191,39 @@ namespace ARW.Service.Business.BusinessService.GoodsManager.Goodss
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 查询全部商品列表
|
||||
/// </summary>
|
||||
public async Task<List<AllGoodsVo>> GetAllGoodsList(GoodsQueryDto parm)
|
||||
{
|
||||
|
||||
//开始拼装查询条件d
|
||||
var predicate = Expressionable.Create<Goods>();
|
||||
|
||||
predicate = predicate.AndIF(parm.ShopGuid != 0, s => s.ShopGuid == parm.ShopGuid);
|
||||
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.GoodsName), s => s.GoodsName.Contains(parm.GoodsName));
|
||||
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.GoodsCoding), s => s.GoodsCoding.Contains(parm.GoodsCoding));
|
||||
var query = _GoodsRepository
|
||||
.Queryable()
|
||||
.Where(predicate.ToExpression())
|
||||
.OrderBy(s => s.GoodsSort, OrderByType.Asc)
|
||||
.Select(s => new AllGoodsVo
|
||||
{
|
||||
GoodsId = s.GoodsId,
|
||||
GoodsGuid = s.GoodsGuid,
|
||||
GoodsName = s.GoodsName,
|
||||
GoodsPicture = s.GoodsPicture,
|
||||
GoodsPriceLowest = s.GoodsPriceLowest,
|
||||
GoodsDashedPriceLowest = s.GoodsDashedPriceLowest,
|
||||
GoodsShelfStatus = s.GoodsShelfStatus,
|
||||
GoodsSort = s.GoodsSort,
|
||||
});
|
||||
|
||||
|
||||
return await query.ToListAsync();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 添加或修改商品
|
||||
|
@ -0,0 +1,185 @@
|
||||
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 Infrastructure;
|
||||
using ARW.Model;
|
||||
using ARW.Repository;
|
||||
using ARW.Repository.Business.Marketing.CouponManage.Coupons;
|
||||
using ARW.Service.Business.IBusinessService.Marketing.CouponManage.Coupons;
|
||||
using ARW.Model.Dto.Business.Marketing.CouponManage.Coupons;
|
||||
using ARW.Model.Models.Business.Marketing.CouponManage.Coupons;
|
||||
using ARW.Model.Vo.Business.Marketing.CouponManage.Coupons;
|
||||
|
||||
namespace ARW.Service.Business.BusinessService.Marketing.CouponManage.Coupons
|
||||
{
|
||||
/// <summary>
|
||||
/// 优惠券接口实现类
|
||||
///
|
||||
/// @author lwh
|
||||
/// @date 2023-07-24
|
||||
/// </summary>
|
||||
[AppService(ServiceType = typeof(ICouponService), ServiceLifetime = LifeTime.Transient)]
|
||||
public class CouponServiceImpl : BaseService<Coupon>, ICouponService
|
||||
{
|
||||
private readonly CouponRepository _CouponRepository;
|
||||
|
||||
public CouponServiceImpl(CouponRepository CouponRepository)
|
||||
{
|
||||
this._CouponRepository = CouponRepository;
|
||||
}
|
||||
|
||||
#region 业务逻辑代码
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 查询优惠券分页列表
|
||||
/// </summary>
|
||||
public async Task<PagedInfo<CouponVo>> GetCouponList(CouponQueryDto parm)
|
||||
{
|
||||
//开始拼装查询条件d
|
||||
var predicate = Expressionable.Create<Coupon>();
|
||||
|
||||
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.CouponName), s => s.CouponName == parm.CouponName);
|
||||
predicate = predicate.AndIF(parm.CouponType != null, s => s.CouponType == parm.CouponType);
|
||||
predicate = predicate.AndIF(parm.CouponExpireType != null, s => s.CouponExpireType == parm.CouponExpireType);
|
||||
predicate = predicate.AndIF(parm.CouponApplicableScope != null, s => s.CouponApplicableScope == parm.CouponApplicableScope);
|
||||
predicate = predicate.AndIF(parm.CouponDisplayStatus != null, s => s.CouponDisplayStatus == parm.CouponDisplayStatus);
|
||||
var query = _CouponRepository
|
||||
.Queryable()
|
||||
.Where(predicate.ToExpression())
|
||||
.OrderBy(s => s.CouponSort,OrderByType.Asc)
|
||||
.Select(s => new CouponVo
|
||||
{
|
||||
CouponId = s.CouponId,
|
||||
CouponGuid = s.CouponGuid,
|
||||
CouponName = s.CouponName,
|
||||
CouponType = s.CouponType,
|
||||
CouponDeductionMoney = s.CouponDeductionMoney,
|
||||
CouponDiscountRate = s.CouponDiscountRate,
|
||||
CouponMinConsumeMoney = s.CouponMinConsumeMoney,
|
||||
CouponExpireType = s.CouponExpireType,
|
||||
CouponEffectiveDays = s.CouponEffectiveDays,
|
||||
CouponFixedStartTime = s.CouponFixedStartTime,
|
||||
CouponFixedEndTime = s.CouponFixedEndTime,
|
||||
CouponApplicableScope = s.CouponApplicableScope,
|
||||
CouponSendNumber = s.CouponSendNumber,
|
||||
CouponDisplayStatus = s.CouponDisplayStatus,
|
||||
CouponSort = s.CouponSort,
|
||||
});
|
||||
|
||||
|
||||
return await query.ToPageAsync(parm);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加或修改优惠券
|
||||
/// </summary>
|
||||
public async Task<string> AddOrUpdateCoupon(Coupon model)
|
||||
{
|
||||
if (model.CouponId != 0)
|
||||
{
|
||||
var response = await _CouponRepository.UpdateAsync(model);
|
||||
return "修改成功!";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
var response = await _CouponRepository.InsertReturnSnowflakeIdAsync(model);
|
||||
return "添加成功!";
|
||||
}
|
||||
}
|
||||
|
||||
#region Excel处理
|
||||
/// <summary>
|
||||
/// 数据导入处理
|
||||
/// </summary>
|
||||
public async Task<CouponVo> HandleImportData(CouponVo Coupon)
|
||||
{
|
||||
return Coupon;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Excel导入
|
||||
/// </summary>
|
||||
public async Task<string> ImportExcel(Coupon Coupon,int index,bool isUpdateSupport,string user)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 空值判断
|
||||
// if (Coupon.CouponId == null) throw new CustomException("优惠券不能为空");
|
||||
|
||||
if (isUpdateSupport)
|
||||
{
|
||||
// 判断唯一值
|
||||
var model = await GetFirstAsync(s => s.CouponId == Coupon.CouponId);
|
||||
|
||||
// 如果为空就新增数据
|
||||
if (model == null)
|
||||
{
|
||||
// 开启事务
|
||||
var res = await UseTranAsync(async () =>
|
||||
{
|
||||
var addRes = await AddOrUpdateCoupon(Coupon);
|
||||
});
|
||||
var addStr = $"第 {index} 行 => 优惠券:【{Coupon.CouponId}】<span style='color:#27af49'>新增成功!</span><br>";
|
||||
return addStr;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 如果有数据就进行修改
|
||||
// 开启事务
|
||||
await UseTranAsync(async () =>
|
||||
{
|
||||
Coupon.CouponId = model.CouponId;
|
||||
Coupon.CouponGuid = model.CouponGuid;
|
||||
Coupon.Update_by = user;
|
||||
Coupon.Update_time = DateTime.Now;
|
||||
var editRes = await AddOrUpdateCoupon(Coupon);
|
||||
});
|
||||
var editStr = $"第 {index} 行 => 优惠券:【{Coupon.CouponId}】<span style='color:#e6a23c'>更新成功!</span><br>";
|
||||
return editStr;
|
||||
}
|
||||
}
|
||||
else{
|
||||
// 开启事务
|
||||
var res = await UseTranAsync(async () =>
|
||||
{
|
||||
var addRes = await AddOrUpdateCoupon(Coupon);
|
||||
});
|
||||
//Console.WriteLine(res.IsSuccess);
|
||||
var addStr = $"第 {index} 行 => 优惠券:【{Coupon.CouponId}】<span style='color:#27af49'>新增成功!</span><br>";
|
||||
return addStr;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var errorRes = $"第 {index} 行 => 优惠券:【{Coupon.CouponId}】<span style='color:red'>导入失败!{ex.Message}</span><br>";
|
||||
return errorRes;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Excel数据导出处理
|
||||
/// </summary>
|
||||
public async Task<List<CouponVo>> HandleExportData(List<CouponVo> data)
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
@ -27,6 +27,14 @@ namespace ARW.Service.Business.IBusinessService.GoodsManager.Goodss
|
||||
Task<PagedInfo<GoodsVo>> GetGoodsList(GoodsQueryDto parm);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取全部商品列表
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<AllGoodsVo>> GetAllGoodsList(GoodsQueryDto parm);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 添加或修改商品
|
||||
/// </summary>
|
||||
|
@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ARW.Model;
|
||||
using ARW.Model.Dto.Business.Marketing.CouponManage.Coupons;
|
||||
using ARW.Model.Models.Business.Marketing.CouponManage.Coupons;
|
||||
using ARW.Model.Vo.Business.Marketing.CouponManage.Coupons;
|
||||
|
||||
namespace ARW.Service.Business.IBusinessService.Marketing.CouponManage.Coupons
|
||||
{
|
||||
/// <summary>
|
||||
/// 优惠券接口类
|
||||
///
|
||||
/// @author lwh
|
||||
/// @date 2023-07-24
|
||||
/// </summary>
|
||||
public interface ICouponService : IBaseService<Coupon>
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取优惠券分页列表
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
Task<PagedInfo<CouponVo>> GetCouponList(CouponQueryDto parm);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 添加或修改优惠券
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
Task<string> AddOrUpdateCoupon(Coupon parm);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 数据导入处理
|
||||
/// </summary>
|
||||
/// <param name="shopVo"></param>
|
||||
/// <returns></returns>
|
||||
Task<CouponVo> HandleImportData(CouponVo CouponVo);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Excel导入
|
||||
/// </summary>
|
||||
/// <param name="Coupon"></param>
|
||||
/// <returns></returns>
|
||||
Task<string> ImportExcel(Coupon Coupon,int index,bool isUpdateSupport,string user);
|
||||
|
||||
/// <summary>
|
||||
/// Excel导出
|
||||
/// </summary>
|
||||
Task<List<CouponVo>> HandleExportData(List<CouponVo> data);
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -89,6 +89,27 @@ namespace ARW.WebApi.Controllers.Business.GoodsManager.Goodss
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取全部商品列表
|
||||
/// </summary>
|
||||
/// <param name="parm">查询参数</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("getAllGoodsList")]
|
||||
public async Task<IActionResult> GetAllGoodsList([FromQuery] GoodsQueryDto parm)
|
||||
{
|
||||
var user = JwtUtil.GetLoginUser(App.HttpContext);
|
||||
if (user.UserId != 1)
|
||||
{
|
||||
var shop = await _ShopService.GetFirstAsync(s => s.ShopUserId == user.UserId);
|
||||
if (shop == null) throw new Exception("当前用户没有店铺");
|
||||
parm.ShopGuid = shop.ShopGuid;
|
||||
}
|
||||
|
||||
var res = await _GoodsService.GetAllGoodsList(parm);
|
||||
return SUCCESS(res);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取商品Sku
|
||||
/// </summary>
|
||||
|
@ -0,0 +1,180 @@
|
||||
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.Model.Dto.Business.Marketing.CouponManage.Coupons;
|
||||
using ARW.Service.Business.IBusinessService.Marketing.CouponManage.Coupons;
|
||||
using ARW.Admin.WebApi.Controllers;
|
||||
using ARW.Model.Models.Business.Marketing.CouponManage.Coupons;
|
||||
using ARW.Model.Vo.Business.Marketing.CouponManage.Coupons;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using ARW.Admin.WebApi.Framework;
|
||||
|
||||
|
||||
namespace ARW.WebApi.Controllers.Business.Marketing.CouponManage.Coupons
|
||||
{
|
||||
/// <summary>
|
||||
/// 优惠券控制器
|
||||
///
|
||||
/// @author lwh
|
||||
/// @date 2023-07-24
|
||||
/// </summary>
|
||||
[Verify]
|
||||
[Route("business/[controller]")]
|
||||
public class CouponController : BaseController
|
||||
{
|
||||
private readonly ICouponService _CouponService;
|
||||
|
||||
/// <summary>
|
||||
/// 依赖注入
|
||||
/// </summary>
|
||||
/// <param name="CouponService">优惠券服务</param>
|
||||
public CouponController(ICouponService CouponService)
|
||||
{
|
||||
_CouponService = CouponService;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取优惠券列表
|
||||
/// </summary>
|
||||
/// <param name="parm">查询参数</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("getCouponList")]
|
||||
[ActionPermissionFilter(Permission = "business:coupon:list")]
|
||||
public async Task<IActionResult> GetCouponList([FromQuery] CouponQueryDto parm)
|
||||
{
|
||||
var res = await _CouponService.GetCouponList(parm);
|
||||
return SUCCESS(res);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加或修改优惠券
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("addOrUpdateCoupon")]
|
||||
[ActionPermissionFilter(Permission = "business:coupon:addOrUpdate")]
|
||||
[Log(Title = "添加或修改优惠券", BusinessType = BusinessType.ADDORUPDATE)]
|
||||
public async Task<IActionResult> AddOrUpdateCoupon([FromBody] CouponDto parm)
|
||||
{
|
||||
if (parm == null) { throw new CustomException("请求参数错误"); }
|
||||
|
||||
var modal = new Coupon();
|
||||
if (parm.CouponId != 0) modal = parm.Adapt<Coupon>().ToUpdate(HttpContext);
|
||||
else modal = parm.Adapt<Coupon>().ToCreate(HttpContext);
|
||||
|
||||
var res = await _CouponService.AddOrUpdateCoupon(modal);
|
||||
return SUCCESS(res);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除优惠券
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("{ids}")]
|
||||
[ActionPermissionFilter(Permission = "business:coupon:delete")]
|
||||
[Log(Title = "优惠券删除", BusinessType = BusinessType.DELETE)]
|
||||
public IActionResult Delete(string ids)
|
||||
{
|
||||
long[] idsArr = Tools.SpitLongArrary(ids);
|
||||
if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); }
|
||||
var response = _CouponService.Delete(idsArr);
|
||||
return SUCCESS("删除成功!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导入优惠券
|
||||
/// </summary>
|
||||
/// <param name="formFile">使用IFromFile必须使用name属性否则获取不到文件</param>
|
||||
/// <param name="updateSupport">是否需要更新</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("importData")]
|
||||
[Log(Title = "优惠券导入", BusinessType = BusinessType.IMPORT, IsSaveRequestData = false, IsSaveResponseData = false)]
|
||||
[ActionPermissionFilter(Permission = "business:coupon:import")]
|
||||
public async Task<IActionResult> ImportExcel([FromForm(Name = "file")] IFormFile formFile,bool updateSupport)
|
||||
{
|
||||
var isUpdateSupport = updateSupport;
|
||||
IEnumerable<CouponVo> parm = ExcelHelper<CouponVo>.ImportData(formFile.OpenReadStream());
|
||||
|
||||
var i = 0;
|
||||
var msgList = new List<string>();
|
||||
foreach (CouponVo item in parm)
|
||||
{
|
||||
i++;
|
||||
var Coupon = await _CouponService.HandleImportData(item);
|
||||
var modal = Coupon.Adapt<Coupon>().ToCreate(HttpContext);
|
||||
var user = JwtUtil.GetLoginUser(App.HttpContext).UserName;
|
||||
var msg = await _CouponService.ImportExcel(modal,i,isUpdateSupport,user);
|
||||
msgList.Add(msg);
|
||||
}
|
||||
|
||||
return SUCCESS(msgList.ToArray());
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 优惠券导入模板下载
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("importTemplate")]
|
||||
[Log(Title = "优惠券模板", BusinessType = BusinessType.EXPORT, IsSaveRequestData = false, IsSaveResponseData = false)]
|
||||
[AllowAnonymous]
|
||||
public IActionResult ImportTemplateExcel()
|
||||
{
|
||||
List<CouponVo> Coupon = new List<CouponVo>();
|
||||
MemoryStream stream = new MemoryStream();
|
||||
|
||||
// 示例数据
|
||||
var values = new List<string>() { "111", "222", "333" };
|
||||
string sFileName = DownloadImportTemplate(Coupon, stream, "优惠券导入模板", values);
|
||||
|
||||
return File(stream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", $"{sFileName}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导出优惠券
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Log(Title = "优惠券导出", BusinessType = BusinessType.EXPORT, IsSaveResponseData = false)]
|
||||
[HttpGet("exportCoupon")]
|
||||
[ActionPermissionFilter(Permission = "business:coupon:export")]
|
||||
public async Task<IActionResult> ExportExcel([FromQuery] CouponQueryDto parm)
|
||||
{
|
||||
parm.PageSize = 10000;
|
||||
var list = await _CouponService.GetCouponList(parm);
|
||||
var data = list.Result;
|
||||
|
||||
// 选中数据
|
||||
if (!string.IsNullOrEmpty(parm.ids))
|
||||
{
|
||||
int[] idsArr = Tools.SpitIntArrary(parm.ids);
|
||||
var selectDataList = new List<CouponVo>();
|
||||
foreach (var item in idsArr)
|
||||
{
|
||||
var select_data = data.Where(s => s.CouponId == item).First();
|
||||
selectDataList.Add(select_data);
|
||||
}
|
||||
data = selectDataList;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 导出数据处理
|
||||
var handleData = await _CouponService.HandleExportData(data);
|
||||
|
||||
string sFileName = ExportExcel(handleData, "Coupon", "优惠券列表");
|
||||
return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName });
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user