mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2025-12-06 18:03:27 +08:00
【新增】优惠券增加发放功能,可以将优惠券发放到特定用户内。
This commit is contained in:
@@ -52,6 +52,7 @@ namespace CoreCms.Net.Web.Admin.Controllers
|
||||
private readonly ICoreCmsPromotionConditionServices _coreCmsPromotionConditionServices;
|
||||
private readonly ICoreCmsPromotionResultServices _coreCmsPromotionResultServices;
|
||||
private readonly ICoreCmsCouponServices _coreCmsCouponServices;
|
||||
private readonly ICoreCmsUserServices _userServices;
|
||||
private readonly ICoreCmsGoodsServices _goodsServices;
|
||||
|
||||
|
||||
@@ -67,7 +68,7 @@ namespace CoreCms.Net.Web.Admin.Controllers
|
||||
, ICoreCmsUserGradeServices coreCmsUserGradeServices
|
||||
, ICoreCmsPromotionConditionServices coreCmsPromotionConditionServices
|
||||
, ICoreCmsPromotionResultServices coreCmsPromotionResultServices
|
||||
, ICoreCmsCouponServices coreCmsCouponServices, ICoreCmsGoodsServices goodsServices)
|
||||
, ICoreCmsCouponServices coreCmsCouponServices, ICoreCmsGoodsServices goodsServices, ICoreCmsUserServices userServices)
|
||||
{
|
||||
_webHostEnvironment = webHostEnvironment;
|
||||
_coreCmsPromotionServices = coreCmsPromotionServices;
|
||||
@@ -80,6 +81,7 @@ namespace CoreCms.Net.Web.Admin.Controllers
|
||||
_coreCmsPromotionResultServices = coreCmsPromotionResultServices;
|
||||
_coreCmsCouponServices = coreCmsCouponServices;
|
||||
_goodsServices = goodsServices;
|
||||
_userServices = userServices;
|
||||
}
|
||||
|
||||
#region 获取列表============================================================
|
||||
@@ -415,6 +417,96 @@ namespace CoreCms.Net.Web.Admin.Controllers
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region 分发优惠券============================================================
|
||||
// POST: Api/CoreCmsPromotion/GetGrant
|
||||
/// <summary>
|
||||
/// 分发优惠券
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("分发优惠券")]
|
||||
public async Task<AdminUiCallBack> GetGrant([FromBody] FMIntId entity)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
var model = await _coreCmsPromotionServices.QueryByIdAsync(entity.id);
|
||||
if (model == null)
|
||||
{
|
||||
jm.msg = "不存在此信息";
|
||||
return jm;
|
||||
}
|
||||
jm.code = 0;
|
||||
|
||||
jm.data = new
|
||||
{
|
||||
model
|
||||
};
|
||||
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 分发优惠券提交============================================================
|
||||
// POST: Admins/CoreCmsPromotion/DoGrant
|
||||
/// <summary>
|
||||
/// 分发优惠券提交
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("分发优惠券提交")]
|
||||
public async Task<AdminUiCallBack> DoGrant([FromBody] FMIntId entity)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
var model = await _coreCmsPromotionServices.QueryByIdAsync(entity.id);
|
||||
if (model == null)
|
||||
{
|
||||
jm.msg = "不存在此信息";
|
||||
return jm;
|
||||
}
|
||||
|
||||
if (entity.data == null)
|
||||
{
|
||||
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)
|
||||
{
|
||||
user = await _userServices.QueryByClauseAsync(p => p.id == id, true);
|
||||
}
|
||||
}
|
||||
if (user == null)
|
||||
{
|
||||
jm.msg = "用户查询失败";
|
||||
return jm;
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
#region 删除数据============================================================
|
||||
// POST: Api/CoreCmsPromotion/DoDelete/10
|
||||
/// <summary>
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
<script type="text/html" template lay-done="layui.data.sendParams(d);">
|
||||
<div class="layui-form coreshop-form layui-form-pane" lay-filter="LAY-app-CoreCmsPromotion-grantForm" id="LAY-app-CoreCmsPromotion-grantForm">
|
||||
<input type="hidden" name="id" id="id" value="{{d.params.data.model.id}}" />
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label for="name" class="layui-form-label">优惠券名称</label>
|
||||
<div class="layui-input-inline layui-inline-8">
|
||||
<input class="layui-input" value="{{d.params.data.model.name || '' }}" disabled="disabled" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label for="sort" class="layui-form-label">用户信息</label>
|
||||
<div class="layui-input-inline layui-inline-5">
|
||||
<input type="number" min="0" max="999999" name="data" lay-verType="tips" lay-verify="required|number" class="layui-input" lay-reqText="请输入数字" />
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux">请输入用户手机号码或者用户序列</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item core-hidden">
|
||||
<div class="layui-input-block">
|
||||
<div class="layui-footer">
|
||||
<input type="button" class="layui-btn" lay-submit lay-filter="LAY-app-CoreCmsPromotion-grantForm-submit" id="LAY-app-CoreCmsPromotion-grantForm-submit" value="确认分发">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</script>
|
||||
<script>
|
||||
var debug = layui.setter.debug;
|
||||
layui.data.sendParams = function (d) {
|
||||
//开启调试情况下获取接口赋值数据
|
||||
if (debug) { console.log(d.params.data); }
|
||||
layui.use(['admin', 'form', 'laydate', 'upload', 'coreHelper', 'util', 'view'],
|
||||
function () {
|
||||
var $ = layui.$
|
||||
, form = layui.form
|
||||
, admin = layui.admin
|
||||
, laydate = layui.laydate
|
||||
, upload = layui.upload
|
||||
, util = layui.util
|
||||
, view = layui.view
|
||||
, coreHelper = layui.coreHelper;
|
||||
|
||||
//重载form
|
||||
form.render(null, 'LAY-app-CoreCmsPromotion-grantForm');
|
||||
})
|
||||
};
|
||||
</script>
|
||||
@@ -51,7 +51,8 @@
|
||||
</div>
|
||||
</script>
|
||||
<script type="text/html" id="LAY-app-CoreCmsPromotion-tableBox-bar">
|
||||
<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="couponlist">券码列表</a>
|
||||
<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="couponlist">券码列表</a>
|
||||
<a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="grant">优惠券发放</a>
|
||||
<a class="layui-btn layui-btn-xs" lay-event="edit">设置参数</a>
|
||||
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
|
||||
</script>
|
||||
@@ -132,7 +133,7 @@
|
||||
{ field: 'effectiveDays', title: '有效天数', sort: false, width: 80 },
|
||||
{ field: 'effectiveHours', title: '有效小时', sort: false, width: 80 },
|
||||
{ field: 'isEnable', title: '是否开启', width: 80, templet: '#switch_isEnable', sort: false, unresize: true },
|
||||
{ width: 202, align: 'center', title: '操作', fixed: 'right', toolbar: '#LAY-app-CoreCmsPromotion-tableBox-bar' }
|
||||
{ width: 282, align: 'center', title: '操作', fixed: 'right', toolbar: '#LAY-app-CoreCmsPromotion-tableBox-bar' }
|
||||
]
|
||||
]
|
||||
});
|
||||
@@ -164,6 +165,8 @@
|
||||
doDelete(obj);
|
||||
} else if (obj.event === 'edit') {
|
||||
doEdit(obj)
|
||||
} else if (obj.event === 'grant') {
|
||||
doGrant(obj)
|
||||
}
|
||||
});
|
||||
//执行创建操作
|
||||
@@ -268,6 +271,47 @@
|
||||
}
|
||||
});
|
||||
}
|
||||
//执行分发操作
|
||||
function doGrant(obj) {
|
||||
coreHelper.Post("Api/CoreCmsPromotion/GetGrant", { id: obj.data.id }, function (e) {
|
||||
if (e.code === 0) {
|
||||
admin.popup({
|
||||
shadeClose: false,
|
||||
title: '分发优惠券',
|
||||
area: ['600px', '300px'],
|
||||
id: 'LAY-popup-CoreCmsPromotion-edit',
|
||||
success: function (layero, index) {
|
||||
view(this.id).render('promotion/coupon/grant', { data: e.data }).done(function () {
|
||||
//监听提交
|
||||
form.on('submit(LAY-app-CoreCmsPromotion-grantForm-submit)',
|
||||
function (data) {
|
||||
var field = data.field; //获取提交的字段
|
||||
|
||||
if (debug) { console.log(field); } //开启调试返回数据
|
||||
//提交 Ajax 成功后,关闭当前弹层并重载表格
|
||||
coreHelper.Post("Api/CoreCmsPromotion/DoGrant", field, function (e) {
|
||||
console.log(e)
|
||||
if (e.code === 0) {
|
||||
layui.table.reloadData('LAY-app-CoreCmsPromotion-tableBox'); //重载表格
|
||||
layer.close(index); //再执行关闭
|
||||
layer.msg(e.msg);
|
||||
} else {
|
||||
layer.msg(e.msg);
|
||||
}
|
||||
});
|
||||
});
|
||||
})
|
||||
}
|
||||
, btn: ['确定', '取消']
|
||||
, yes: function (index, layero) {
|
||||
layero.contents().find("#LAY-app-CoreCmsPromotion-grantForm-submit").click();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
layer.msg(e.msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
//执行单个删除
|
||||
function doDelete(obj) {
|
||||
layer.confirm('确定删除吗?删除后将无法恢复。', function (index) {
|
||||
|
||||
Reference in New Issue
Block a user