mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2025-12-06 17:43:26 +08:00
【新增】后端分发优惠券增加按用户组分发的队列功能。
This commit is contained in:
@@ -14,6 +14,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.Caching.AutoMate.RedisCache;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.Filter;
|
||||
using CoreCms.Net.IServices;
|
||||
@@ -28,6 +29,7 @@ using CoreCms.Net.Web.Admin.Infrastructure;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
using NPOI.HSSF.UserModel;
|
||||
using SqlSugar;
|
||||
|
||||
@@ -55,7 +57,7 @@ namespace CoreCms.Net.Web.Admin.Controllers
|
||||
private readonly ICoreCmsCouponServices _coreCmsCouponServices;
|
||||
private readonly ICoreCmsUserServices _userServices;
|
||||
private readonly ICoreCmsGoodsServices _goodsServices;
|
||||
|
||||
private readonly IRedisOperationRepository _redisOperationRepository;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
@@ -69,7 +71,7 @@ namespace CoreCms.Net.Web.Admin.Controllers
|
||||
, ICoreCmsUserGradeServices coreCmsUserGradeServices
|
||||
, ICoreCmsPromotionConditionServices coreCmsPromotionConditionServices
|
||||
, ICoreCmsPromotionResultServices coreCmsPromotionResultServices
|
||||
, ICoreCmsCouponServices coreCmsCouponServices, ICoreCmsGoodsServices goodsServices, ICoreCmsUserServices userServices)
|
||||
, ICoreCmsCouponServices coreCmsCouponServices, ICoreCmsGoodsServices goodsServices, ICoreCmsUserServices userServices, IRedisOperationRepository redisOperationRepository)
|
||||
{
|
||||
_webHostEnvironment = webHostEnvironment;
|
||||
_coreCmsPromotionServices = coreCmsPromotionServices;
|
||||
@@ -83,6 +85,7 @@ namespace CoreCms.Net.Web.Admin.Controllers
|
||||
_coreCmsCouponServices = coreCmsCouponServices;
|
||||
_goodsServices = goodsServices;
|
||||
_userServices = userServices;
|
||||
_redisOperationRepository = redisOperationRepository;
|
||||
}
|
||||
|
||||
#region 获取列表============================================================
|
||||
@@ -438,11 +441,15 @@ namespace CoreCms.Net.Web.Admin.Controllers
|
||||
jm.msg = "不存在此信息";
|
||||
return jm;
|
||||
}
|
||||
|
||||
var userGrade = await _coreCmsUserGradeServices.QueryAsync(false, true);
|
||||
|
||||
jm.code = 0;
|
||||
|
||||
jm.data = new
|
||||
{
|
||||
model
|
||||
model,
|
||||
userGrade
|
||||
};
|
||||
|
||||
return jm;
|
||||
@@ -458,7 +465,7 @@ namespace CoreCms.Net.Web.Admin.Controllers
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("分发优惠券提交")]
|
||||
public async Task<AdminUiCallBack> DoGrant([FromBody] FMIntId entity)
|
||||
public async Task<AdminUiCallBack> DoGrant([FromBody] FMCouponDistribution entity)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
@@ -469,41 +476,42 @@ namespace CoreCms.Net.Web.Admin.Controllers
|
||||
return jm;
|
||||
}
|
||||
|
||||
if (entity.data == null)
|
||||
//单人分发模式
|
||||
if (entity.distributionMode == (int)GlobalEnumVars.CouponDistributionMode.Single)
|
||||
{
|
||||
jm.msg = "请输入合法的序列或手机号码";
|
||||
return jm;
|
||||
}
|
||||
|
||||
var userId = entity.data.ObjectToString();
|
||||
|
||||
CoreCmsUser user = null;
|
||||
if (CommonHelper.IsMobile(userId))
|
||||
{
|
||||
user = await _userServices.QueryByClauseAsync(p => p.mobile == userId, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
int id = 0;
|
||||
var isInt = int.TryParse(userId, out id);
|
||||
if (isInt && id > 0)
|
||||
if (entity.userIdOrMobile == 0)
|
||||
{
|
||||
user = await _userServices.QueryByClauseAsync(p => p.id == id, true);
|
||||
jm.msg = "请输入合法的序列或手机号码";
|
||||
return jm;
|
||||
}
|
||||
CoreCmsUser user = null;
|
||||
if (CommonHelper.IsMobile(entity.userIdOrMobile.ToString()))
|
||||
{
|
||||
user = await _userServices.QueryByClauseAsync(p => p.mobile == entity.userIdOrMobile.ToString(), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
user = await _userServices.QueryByClauseAsync(p => p.id == entity.userIdOrMobile, true);
|
||||
}
|
||||
if (user == null)
|
||||
{
|
||||
jm.msg = "用户查询失败";
|
||||
return jm;
|
||||
}
|
||||
|
||||
var result = await _coreCmsCouponServices.AddData(user.id, entity.id, model);
|
||||
|
||||
jm.code = result.status ? 0 : 1;
|
||||
jm.msg = result.status ? "发放成功" : "发放失败";
|
||||
}
|
||||
if (user == null)
|
||||
// 用户组分发模式
|
||||
else if (entity.distributionMode == (int)GlobalEnumVars.CouponDistributionMode.UserGroup)
|
||||
{
|
||||
jm.msg = "用户查询失败";
|
||||
return jm;
|
||||
await _redisOperationRepository.ListLeftPushAsync(RedisMessageQueueKey.CouponDistributionSubscribe, JsonConvert.SerializeObject(entity));
|
||||
|
||||
jm.code = 0;
|
||||
jm.msg = "已经提交消息队列。";
|
||||
}
|
||||
|
||||
var result = await _coreCmsCouponServices.AddData(user.id, entity.id, model);
|
||||
|
||||
//事物处理过程结束
|
||||
var bl = result.status;
|
||||
jm.code = bl ? 0 : 1;
|
||||
jm.msg = bl ? "发放成功" : "发放失败";
|
||||
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
@@ -859,7 +867,8 @@ namespace CoreCms.Net.Web.Admin.Controllers
|
||||
{
|
||||
jm.msg = GlobalErrorCodeVars.Code15016;
|
||||
return jm;
|
||||
} else if (model.type == (int)GlobalEnumVars.PromotionType.Coupon)
|
||||
}
|
||||
else if (model.type == (int)GlobalEnumVars.PromotionType.Coupon)
|
||||
{
|
||||
jm.msg = GlobalErrorCodeVars.Code15030;
|
||||
return jm;
|
||||
|
||||
Reference in New Issue
Block a user