예제 #1
0
        public async Task <JsonResult> GetActivityModels(int pageIndex = 1, int pageSize = 10)
        {
            using (var client = new ActivityClient())
            {
                var result = await client.GetActivityModelsPagedAsync(pageIndex, pageSize);

                if (result.Success)
                {
                    foreach (var activity in result.Result.Item1)
                    {
                        var applyUserCountResult =
                            await client.GetActivityApplyUserCountByActivityIdAsync(activity.ActivityId);

                        var auditPassUserCount =
                            await client.GetActivityApplyUserPassCountByActivityIdAsync(activity.ActivityId);

                        activity.ApplyUserCount     = applyUserCountResult.Success ? applyUserCountResult.Result : 0;
                        activity.AuditPassUserCount = auditPassUserCount.Success ? auditPassUserCount.Result : 0;
                    }
                    return(AjaxHelper.MvcJsonResult(HttpStatusCode.OK, "成功", result.Result));
                }
                else
                {
                    return(AjaxHelper.MvcJsonResult(HttpStatusCode.BadGateway, "服务器内部错误"));
                }
            }
        }
예제 #2
0
        public async Task <JsonResult> GetUserActivityModels(Guid activityId, Service.Activity.Enum.AuditStatus auditStatus = Service.Activity.Enum.AuditStatus.None, int pageIndex = 1, int pageSize = 10)
        {
            using (var client = new ActivityClient())
            {
                var result = await client.GetUserApplyActivityModelsPagedAsync(activityId, auditStatus, pageIndex, pageSize);

                if (result.Success)
                {
                    return(AjaxHelper.MvcJsonResult(HttpStatusCode.OK, "成功", result.Result));
                }
                return(AjaxHelper.MvcJsonResult(HttpStatusCode.BadGateway, "服务器内部错误"));
            }
        }
예제 #3
0
        public async Task <JsonResult> CreateOrUpdateActivity(ActivityNewModel activityModel)
        {
            if (string.IsNullOrEmpty(activityModel.Name))
            {
                return(AjaxHelper.MvcJsonResult(HttpStatusCode.BadRequest, "活动名称不能为空"));
            }
            var dateNow = DateTime.Now.Date;

            if (activityModel.StartTime < dateNow || activityModel.EndTime <= dateNow)
            {
                return(AjaxHelper.MvcJsonResult(HttpStatusCode.BadRequest, "活动开始时间或结束时间不能小于当前时间"));
            }
            if (activityModel.EndTime <= activityModel.StartTime)
            {
                return(AjaxHelper.MvcJsonResult(HttpStatusCode.BadRequest, "活动结束时间不能小于等于活动开始时间"));
            }
            if (activityModel.Quota <= 0)
            {
                return(AjaxHelper.MvcJsonResult(HttpStatusCode.BadRequest, "活动限购不能小于等于0"));
            }

            activityModel.CreateUser = HttpContext.User.Identity.Name;
            using (var client = new ActivityClient())
            {
                if (activityModel.PKID > 0)//更新活动
                {
                    var result = await client.UpdateActivityModelAsync(activityModel);

                    //刷新活动缓存
                    var recacheResult = await client.RefreshActivityModelByActivityIdCacheAsync(activityModel.ActivityId);

                    if (!result.Success || !recacheResult.Success)
                    {
                        return(AjaxHelper.MvcJsonResult(HttpStatusCode.BadGateway, "服务器内部错误"));
                    }
                }
                else//创建活动
                {
                    activityModel.ActivityId  = Guid.NewGuid();
                    activityModel.ActivityUrl = WashCarActivityUrlPrefix + activityModel.ActivityId;
                    var result = await client.InsertActivityModelAsync(activityModel);

                    if (!result.Success)
                    {
                        return(AjaxHelper.MvcJsonResult(HttpStatusCode.BadGateway, "服务器内部错误"));
                    }
                }
            }
            return(AjaxHelper.MvcJsonResult(HttpStatusCode.OK, "成功"));
        }
예제 #4
0
        public async Task <JsonResult> DeleteUserActivityByPKID(int pkid)
        {
            if (pkid <= 0)
            {
                return(AjaxHelper.MvcJsonResult(HttpStatusCode.BadRequest, "缺少必要参数"));
            }
            using (var client = new ActivityClient())
            {
                var result = await client.DeleteUserApplyActivityModelByPKIDAsync(pkid);

                if (result.Success && result.Result)
                {
                    return(AjaxHelper.MvcJsonResult(HttpStatusCode.OK, "成功"));
                }
                return(AjaxHelper.MvcJsonResult(HttpStatusCode.BadGateway, "失败"));
            }
        }
예제 #5
0
        public async Task <JsonResult> DeleteActivityByActivityId(Guid activityId)
        {
            if (activityId == Guid.Empty)
            {
                return(AjaxHelper.MvcJsonResult(HttpStatusCode.BadRequest, "缺少必要参数"));
            }
            using (var activityClient = new ActivityClient())
            {
                var result = await activityClient.DeleteActivityModelByActivityIdAsync(activityId);

                if (result.Success && result.Result)
                {
                    //移除活动缓存
                    await activityClient.RemoveActivityModelByActivityIdCacheAsync(activityId);

                    return(AjaxHelper.MvcJsonResult(HttpStatusCode.OK, "成功"));
                }
                return(AjaxHelper.MvcJsonResult(HttpStatusCode.BadGateway, "失败"));
            }
        }
예제 #6
0
        public async Task <JsonResult> AuditUserActivityStatusByPKID(int pkid, Guid activityId, Service.Activity.Enum.AuditStatus status, string remark)
        {
            if (pkid <= 0 || activityId == Guid.Empty || status != Service.Activity.Enum.AuditStatus.NotPassed && status != Service.Activity.Enum.AuditStatus.Passed)
            {
                return(AjaxHelper.MvcJsonResult(HttpStatusCode.BadRequest, "参数不完整"));
            }
            string sendText;
            var    userActivity = new UserApplyActivityModel
            {
                PKID   = pkid,
                Remark = remark,
                Status = status
            };

            if (status == Service.Activity.Enum.AuditStatus.Passed)
            {
                using (var client = new ActivityClient())
                {
                    var activity = await client.GetActivityModelByActivityIdAsync(activityId);

                    if (activity.Success)
                    {
                        if (!await CheckApplyUserCountAsync(activityId, activity.Result.Quota))
                        {
                            return(AjaxHelper.MvcJsonResult(HttpStatusCode.Accepted, "活动审核通过人数已满"));
                        }
                    }
                    else
                    {
                        return(AjaxHelper.MvcJsonResult(HttpStatusCode.BadGateway, "服务器内部错误"));
                    }
                }
                var serviceCode = Guid.NewGuid();
                sendText = serviceCode.ToString();
                userActivity.ServiceCode = serviceCode;
            }
            else
            {
                sendText = $"抱歉,您报名途虎免费洗车活动审核未通过。备注:{remark}";
            }
            using (var activityClient = new ActivityClient())
            {
                var result = await activityClient.UpdateUserActivityStatusByPKIDAsync(userActivity);

                if (result.Success && result.Result)
                {
                    //短信发送服务码
                    var ua = await activityClient.GetUserApplyActivityByPKIDAsync(pkid);

                    if (ua.Success)
                    {
                        using (var client = new Service.Utility.SmsClient())
                        {
                            var sendResult = client.SendSms(ua.Result.Mobile, 138, sendText);
                            if (sendResult.Success)
                            {
                                return(AjaxHelper.MvcJsonResult(HttpStatusCode.OK, "审核成功"));
                            }
                        }
                    }
                    return(AjaxHelper.MvcJsonResult(HttpStatusCode.OK, "审核成功,但短信发送失败。"));
                }
            }
            return(AjaxHelper.MvcJsonResult(HttpStatusCode.BadGateway, "审核失败"));
        }