Commit b67b8eac authored by 吴春's avatar 吴春

提交代码

parent 727c6330
......@@ -19,10 +19,12 @@ namespace Mall.Model.Extend.MarketingCenter
public List<RB_DiscountCoupon_Product_Extend> ProductList { get; set; }
/// <summary>
/// 发放优惠券的时候会员id
/// 发放优惠券的时候会员ids
/// </summary>
public string UserIds { get; set; }
/// <summary>
/// 发放数量
/// </summary>
......@@ -36,5 +38,13 @@ namespace Mall.Model.Extend.MarketingCenter
/// 会员等级
/// </summary>
public int[] MemberLevelList { get; set; }
/// <summary>
/// 发放优惠券的时候会员id
/// </summary>
public int UserId { get; set; }
}
}
......@@ -17,5 +17,16 @@ namespace Mall.Model.Extend.MarketingCenter
/// 关联信息(商品图片/分类名称)
/// </summary>
public string Relevance { get; set; }
/// <summary>
/// 商品价格(下单获取优惠券)
/// </summary>
public decimal GoodsPrice { get; set; }
/// <summary>
/// 商品分类id
/// </summary>
public int[] GoodsClassId { get; set; }
}
}
......@@ -57,5 +57,8 @@ namespace Mall.Model.Extend.User
/// 优惠卷ids
/// </summary>
public string CouponIds { get; set; }
}
}
......@@ -178,6 +178,7 @@ namespace Mall.Module.MarketingCenter
id = discountCouponRepository.Insert(model, trans);
if (id > 0 && model.ProductList != null && model.ProductList.Any())
{
model.ProductList.ForEach(x => x.DiscountCouponType = model.UseType);
model.ProductList.ForEach(x => x.MallBaseId = model.MallBaseId);
model.ProductList.ForEach(x => x.TenantId = model.TenantId);
model.ProductList.ForEach(x => x.CreateDate = model.CreateDate);
......@@ -202,7 +203,7 @@ namespace Mall.Module.MarketingCenter
{
new WhereHelper (){ FiledName=nameof(RB_DiscountCoupon_Product.DiscountCouponId),FiledValue=id,OperatorEnum=OperatorEnum.Equal}
};
productRepository.Update(fileds, whereHelpers, trans);
productRepository.Update(fileds, whereHelpers, trans);
////var listProduct = productRepository.GetCouponProductList(new RB_DiscountCoupon_Product { TenantId = model.TenantId, MallBaseId = model.MallBaseId, DiscountCouponId = id });
////if (listProduct != null && listProduct.Any())
////{
......@@ -223,6 +224,7 @@ namespace Mall.Module.MarketingCenter
if (model.ProductList != null && model.ProductList.Any())
{
model.ProductList.ForEach(x => x.DiscountCouponType = model.UseType);
model.ProductList.ForEach(x => x.MallBaseId = model.MallBaseId);
model.ProductList.ForEach(x => x.TenantId = model.TenantId);
model.ProductList.ForEach(x => x.CreateDate = model.CreateDate);
......@@ -412,6 +414,19 @@ namespace Mall.Module.MarketingCenter
}
return flag;
}
/// <summary>
/// 根据用户id和商品分类以及商品id获取未使用的优惠券信息
/// </summary>
/// <param name="query">查询条件</param>
/// <returns></returns>
public List<RB_DiscountCoupon_Extend> GetNoUseCouponList(RB_DiscountCoupon_Extend query)
{
return discountCouponRepository.GetNoUseCouponList(query);
}
#endregion
#region 自动发放优惠券规则
......@@ -439,7 +454,7 @@ namespace Mall.Module.MarketingCenter
public List<RB_Coupon_SelfMotion_Extend> GettRepositoryList(RB_Coupon_SelfMotion_Extend query)
{
var list = selfMotionRepository.GettRepositoryList(query);
return list;
}
......@@ -486,7 +501,7 @@ namespace Mall.Module.MarketingCenter
{
id = model.ID;
flag = selfMotionRepository.Update(model, trans);
// var listProduct = selfMotionMemberRepository.GetListRepository(new RB_Coupon_SelfMotionMember_Extend { TenantId = model.TenantId, MallBaseId = model.MallBaseId, SelfMotionId = id });
// var listProduct = selfMotionMemberRepository.GetListRepository(new RB_Coupon_SelfMotionMember_Extend { TenantId = model.TenantId, MallBaseId = model.MallBaseId, SelfMotionId = id });
//if (listProduct != null && listProduct.Any())
//{
// foreach (var item in model.UserList)
......@@ -514,7 +529,7 @@ namespace Mall.Module.MarketingCenter
new WhereHelper (){ FiledName=nameof(RB_Coupon_SelfMotionMember.MallBaseId),FiledValue=model.MallBaseId,OperatorEnum=OperatorEnum.Equal},
new WhereHelper (){ FiledName=nameof(RB_Coupon_SelfMotionMember.TenantId),FiledValue=model.TenantId,OperatorEnum=OperatorEnum.Equal}
};
selfMotionMemberRepository.Update(fileds, whereHelpers, trans);
selfMotionMemberRepository.Update(fileds, whereHelpers, trans);
if (model.UserList != null && model.UserList.Any())
......
using Mall.Model.Entity.MarketingCenter;
using Mall.Model.Entity.User;
using Mall.Model.Extend.MarketingCenter;
using System;
using System.Collections.Generic;
......@@ -7,12 +8,18 @@ using System.Text;
namespace Mall.Repository.MarketingCenter
{
public class RB_DiscountCouponRepository:RepositoryBase<RB_DiscountCoupon>
public class RB_DiscountCouponRepository : RepositoryBase<RB_DiscountCoupon>
{
/// <summary>
/// 表名称
/// </summary>
public string TableName { get { return nameof(RB_DiscountCoupon); } }
/// <summary>
/// 表名称
/// </summary>
public string discountCouponTableName { get { return nameof(RB_Member_DiscountCoupon); } }
/// <summary>
/// 卡券信息列表
/// </summary>
......@@ -71,12 +78,111 @@ namespace Mall.Repository.MarketingCenter
{
builder.Append($" AND {nameof(RB_DiscountCoupon_Extend.Name)} like '%{query.Name}%'");
}
if (!string.IsNullOrEmpty(query.CouponIds))
if (!string.IsNullOrEmpty(query.CouponIds))
{
builder.Append($" AND {nameof(RB_DiscountCoupon_Extend.ID)} in({query.CouponIds})");
}
}
return Get<RB_DiscountCoupon_Extend>(builder.ToString()).ToList();
}
/// <summary>
/// 根据用户id和商品分类以及商品id获取未使用的优惠券信息
/// </summary>
/// <param name="query">查询条件</param>
/// <returns></returns>
public List<RB_DiscountCoupon_Extend> GetNoUseCouponList(RB_DiscountCoupon_Extend query)
{
string where = " and a.StartDate<NOW() and a.EndDate>NOW() and b.`Status`=0 ";
string goodsClassWhere = "";//分类
string goodsWhere = "";//商品
string allWhere = "";//通用
if (query != null)
{
if (query.TenantId > 0)
{
where += $" AND b.{nameof(RB_DiscountCoupon_Extend.TenantId)}={query.TenantId}";
}
if (query.MallBaseId > 0)
{
where += $" AND b.{nameof(RB_DiscountCoupon_Extend.MallBaseId)}={query.MallBaseId}";
}
if (query.UserId > 0)
{
where += $" AND a.{nameof(RB_DiscountCoupon_Extend.UserId)}={query.UserId}";
}
if (query.ProductList != null && query.ProductList.Any())
{
List<int> allGoodsClass = new List<int>();
foreach (var item in query.ProductList)
{
if (!string.IsNullOrWhiteSpace(goodsWhere))
{
goodsWhere += $" or (c.ProductId = {item.ProductId} and b.MinConsumePrice<= {item.GoodsPrice}) ";
}
else
{
goodsWhere += $" (c.ProductId = {item.ProductId} and b.MinConsumePrice<= {item.GoodsPrice}) ";
}
allGoodsClass.AddRange(item.GoodsClassId.ToList());
}
goodsWhere = " and (" + goodsWhere + ")";
//分类
var goodsClassList = allGoodsClass.GroupBy(x => x);
foreach (var item in goodsClassList)
{
decimal nowPrice = 0;
foreach (var classItem in query.ProductList)
{
if (classItem.GoodsClassId.Any(x => x == item.Key))
{
nowPrice += classItem.GoodsPrice;
}
}
if (!string.IsNullOrWhiteSpace(goodsClassWhere))
{
goodsClassWhere += $" or (c.ProductId = {item.Key} and b.MinConsumePrice<= {nowPrice}) ";
}
else
{
goodsClassWhere += $" (c.ProductId = {item.Key} and b.MinConsumePrice<= {nowPrice}) ";
}
}
goodsClassWhere = " and (" + goodsClassWhere + ")";
decimal allPrice = query.ProductList.Sum(x => x.GoodsPrice);
allWhere = $" and b.MinConsumePrice<= {allPrice} ";
}
}
string sql = @$" SELECT a.ID,a.UserId,b.`Name`,b.CouponType,b.UseType,b.MinConsumePrice,b.DiscountsPrice,b.MaxDiscountsPrice,b.Describe,a.StartDate,a.EndDate from rb_discountcoupon as b
LEFT JOIN rb_discountcoupon_product as c on b.ID=c.DiscountCouponId
LEFT JOIN rb_member_discountcoupon as a on a.CouponId=b.ID
where b.UseType=1 and c.`Status`=0 {where} {goodsClassWhere}
UNION ALL
SELECT a.ID,a.UserId,b.`Name`,b.CouponType,b.UseType,b.MinConsumePrice,b.DiscountsPrice,b.MaxDiscountsPrice,b.Describe,a.StartDate,a.EndDate from rb_discountcoupon as b
LEFT JOIN rb_discountcoupon_product as c on b.ID=c.DiscountCouponId
LEFT JOIN rb_member_discountcoupon as a on a.CouponId=b.ID
where b.UseType=2 and c.`Status`=0 {where} {goodsWhere}
UNION all
SELECT a.ID,a.UserId,b.`Name`,b.CouponType,b.UseType,b.MinConsumePrice,b.DiscountsPrice,b.MaxDiscountsPrice,b.Describe,a.StartDate,a.EndDate from rb_discountcoupon as b
LEFT JOIN rb_member_discountcoupon as a on a.CouponId=b.ID
where b.UseType=3 {where} {allWhere}";
return Get<RB_DiscountCoupon_Extend>(sql).ToList();
}
}
}
......@@ -55,13 +55,16 @@ namespace Mall.Repository.User
{
builder.Append($" AND a.{nameof(RB_Member_DiscountCoupon_Extend.UserId)}={query.UserId}");
}
if (query.CouponId > 0) {
if (query.CouponId > 0)
{
builder.Append($" AND a.{nameof(RB_Member_DiscountCoupon_Extend.CouponId)}={query.CouponId}");
}
if (!string.IsNullOrEmpty(query.CouponIds)) {
if (!string.IsNullOrEmpty(query.CouponIds))
{
builder.Append($" AND a.{nameof(RB_Member_DiscountCoupon_Extend.CouponId)} in ({query.CouponIds})");
}
if (query.UseState >= 0) {
if (query.UseState >= 0)
{
builder.Append($" AND a.{nameof(RB_Member_DiscountCoupon_Extend.UseState)}={query.UseState}");
}
}
......@@ -69,6 +72,8 @@ namespace Mall.Repository.User
return Get<RB_Member_DiscountCoupon_Extend>(sql).ToList();
}
/// <summary>
/// 会员优惠券
/// </summary>
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Mall.Common;
using Mall.Common.API;
using Mall.Common.Plugin;
using Mall.Model.Extend.MarketingCenter;
using Mall.Module.MarketingCenter;
using Mall.WebApi.Filter;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace Mall.WebApi.Controllers.MarketingCenter
{
[Route("api/[controller]/[action]")]
[ApiExceptionFilter]
[ApiController]
[EnableCors("AllowCors")]
public class AppletCouponController : BaseController
{
private CouponModule couponModule = new CouponModule();
/// <summary>
/// 设置购物车数量
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult GetNoUseCouponList()
{
var req = RequestParm;
var userInfo = AppletUserInfo;
JObject prams = JObject.Parse(req.msg.ToString());
var query = JsonConvert.DeserializeObject<RB_DiscountCoupon_Extend>(RequestParm.msg.ToString());
if (userInfo == null)
{
userInfo.TenantId = 1;
userInfo.MallBaseId = 1;
userInfo.UserId = 3;
}
query.TenantId = userInfo.TenantId;
query.MallBaseId = userInfo.MallBaseId;
query.UserId = userInfo.UserId;
var list = couponModule.GetNoUseCouponList(query);
var result = list.Select(x => new
{
x.ID,
StartDate = x.StartDate.HasValue ? x.StartDate.Value.ToString("yyyy-MM-dd HH:mm:ss") : "",
EndDate = x.EndDate.HasValue ? x.EndDate.Value.ToString("yyyy-MM-dd HH:mm:ss") : "",
x.Name,
x.Describe,
x.MinConsumePrice,
x.CouponType,
x.MaxDiscountsPrice,
x.UseType
});
return ApiResult.Success("", result);
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment