fixed 完善优惠券
This commit is contained in:
parent
be2e90d3aa
commit
064b9fea0a
@ -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; }
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ namespace ARW.Model.Models.Business.Marketing.CouponManage.Coupons
|
||||
/// </summary>
|
||||
[EpplusTableColumn(Header = "适用范围")]
|
||||
[SugarColumn(ColumnName = "coupon_applicable_scope")]
|
||||
public int? CouponApplicableScope { get; set; }
|
||||
public int CouponApplicableScope { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
@ -15,18 +15,17 @@ namespace ARW.Model.Vo.Api.Marketing.CouponManage.CustomerCoupons
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 描述 : CustomerCouponGuid
|
||||
/// 描述 : CouponGuid
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
[JsonIgnore]
|
||||
public long CustomerCouponGuid { get; set; }
|
||||
public long CouponGuid { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 : Key
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
public long Key { get; set; }
|
||||
public int Key { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
@ -76,16 +75,68 @@ namespace ARW.Model.Vo.Api.Marketing.CouponManage.CustomerCoupons
|
||||
/// </summary>
|
||||
public class CustomerCouponApiDetailsVo
|
||||
{
|
||||
public int CustomerCouponId { get; set; }
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
public long CustomerCouponGuid { get; set; }
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
/// <summary>
|
||||
/// 描述 : CouponGuid
|
||||
/// </summary>
|
||||
[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; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 : Key
|
||||
/// </summary>
|
||||
public int 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>
|
||||
/// 适用范围
|
||||
/// </summary>
|
||||
public string StoreAdapt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 使用须知
|
||||
/// </summary>
|
||||
public string UseNotes { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<Coupon>((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<Coupon>((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<CustomerCouponApiDetailsVo>(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();
|
||||
}
|
||||
|
||||
|
||||
|
@ -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<CustomerCouponApiDetailsVo>();
|
||||
return SUCCESS(data);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user