From 8deb3814fc08ec0b2806122361af7f539708c680 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E7=81=B0=E7=81=B0?= Date: Sun, 25 Sep 2022 01:57:59 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=96=B0=E5=A2=9E=E3=80=91=E4=BC=98?= =?UTF-8?q?=E6=83=A0=E5=88=B8=E5=A2=9E=E5=8A=A0=E5=8F=91=E6=94=BE=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=8C=E5=8F=AF=E4=BB=A5=E5=B0=86=E4=BC=98=E6=83=A0?= =?UTF-8?q?=E5=88=B8=E5=8F=91=E6=94=BE=E5=88=B0=E7=89=B9=E5=AE=9A=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E5=86=85=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Promotion/CoreCmsPromotionController.cs | 94 ++++++++++++++++++- .../wwwroot/views/promotion/coupon/grant.html | 49 ++++++++++ .../wwwroot/views/promotion/coupon/index.html | 48 +++++++++- 3 files changed, 188 insertions(+), 3 deletions(-) create mode 100644 CoreCms.Net.Web.Admin/wwwroot/views/promotion/coupon/grant.html diff --git a/CoreCms.Net.Web.Admin/Controllers/Promotion/CoreCmsPromotionController.cs b/CoreCms.Net.Web.Admin/Controllers/Promotion/CoreCmsPromotionController.cs index 3ec9dc2e..a5f87823 100644 --- a/CoreCms.Net.Web.Admin/Controllers/Promotion/CoreCmsPromotionController.cs +++ b/CoreCms.Net.Web.Admin/Controllers/Promotion/CoreCmsPromotionController.cs @@ -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 + /// + /// 分发优惠券 + /// + /// + /// + [HttpPost] + [Description("分发优惠券")] + public async Task 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 + /// + /// 分发优惠券提交 + /// + /// + /// + [HttpPost] + [Description("分发优惠券提交")] + public async Task 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 /// diff --git a/CoreCms.Net.Web.Admin/wwwroot/views/promotion/coupon/grant.html b/CoreCms.Net.Web.Admin/wwwroot/views/promotion/coupon/grant.html new file mode 100644 index 00000000..48d81f39 --- /dev/null +++ b/CoreCms.Net.Web.Admin/wwwroot/views/promotion/coupon/grant.html @@ -0,0 +1,49 @@ + + \ No newline at end of file diff --git a/CoreCms.Net.Web.Admin/wwwroot/views/promotion/coupon/index.html b/CoreCms.Net.Web.Admin/wwwroot/views/promotion/coupon/index.html index 91645eb7..fe75f3fb 100644 --- a/CoreCms.Net.Web.Admin/wwwroot/views/promotion/coupon/index.html +++ b/CoreCms.Net.Web.Admin/wwwroot/views/promotion/coupon/index.html @@ -51,7 +51,8 @@ @@ -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) {