public async Task <JsonResult> UserApplyActivity(UserApplyActivityModel userActivityModel, string userName) { if (userActivityModel.ActivityId == Guid.Empty || string.IsNullOrWhiteSpace(userActivityModel.Mobile) || string.IsNullOrWhiteSpace(userActivityModel.CarNum) || string.IsNullOrWhiteSpace(userActivityModel.DriverNum)) { return(AjaxHelper.MvcJsonResult(HttpStatusCode.BadRequest, "缺少必要参数")); } userActivityModel.UserName = userName; using (var activityClient = new ActivityClient()) { //检查活动是否开始 var activityModel = await activityClient.GetActivityModelByActivityIdAsync(userActivityModel.ActivityId); if (activityModel.Success) { if (activityModel.Result.StartTime > DateTime.Now.Date) { return(AjaxHelper.MvcJsonResult(HttpStatusCode.Accepted, "活动暂未开始")); } } else { return(AjaxHelper.MvcJsonResult(HttpStatusCode.BadGateway, "服务器内部错误")); } //检查用户手机号、车牌号、驾驶证号是否已经使用 var isExistResult = await activityClient.CheckUserApplyActivityInfoIsExistAsync(userActivityModel.ActivityId, userActivityModel.Mobile, userActivityModel.CarNum, userActivityModel.DriverNum); if (isExistResult.Success) { if (!isExistResult.Result) { var activity = await activityClient.GetActivityModelByActivityIdAsync(userActivityModel.ActivityId); //获取报名用户审核通过数 var auditPassCount = await activityClient.GetActivityApplyUserPassCountByActivityIdAsync(userActivityModel .ActivityId); if (activity.Success && auditPassCount.Success && auditPassCount.Result < activity.Result.Quota) { var cacheResult = await activityClient.AddUserApplyActivitySortedSetCacheAsync(userActivityModel); if (cacheResult.Success) { return(AjaxHelper.MvcJsonResult(HttpStatusCode.OK, "报名成功,审核通过后服务码将会以短信形式发送到您的手机,请注意查收")); } } else { return(AjaxHelper.MvcJsonResult(HttpStatusCode.Accepted, "报名人数已满!")); } } else { return(AjaxHelper.MvcJsonResult(HttpStatusCode.Accepted, "手机号、车牌号、驾驶证号已经被使用")); } } } return(AjaxHelper.MvcJsonResult(HttpStatusCode.BadGateway, "服务器内部错误")); }
public async Task TaskMethod() { try { var list = new List <UserApplyActivityModel>(); var noRepeatList = new List <string>(); using (var client = new ActivityClient()) { var result = await client.GetUserApplyActivityRangeByScoreAsync(); if (result.Success) { using (var activityClient = new ActivityClient()) { foreach (var item in result.Result) { if (await CheckApplyUserCountAsync(item.ActivityId)) { //检查用户手机号、车牌号、驾驶证号是否已经使用 var isExist = await activityClient.CheckUserApplyActivityInfoIsExistAsync(item.ActivityId, item.Mobile, item.CarNum, item.DriverNum); if (isExist.Success && !isExist.Result) { User user = null; using (var userClient = new UserAccountClient()) { try { var userResult = userClient.GetUserByMobile(item.Mobile); userResult.ThrowIfException(true); user = userResult.Result; if (user == null) { var createResult = userClient.CreateUserRequest( new CreateUserRequest { MobileNumber = item.Mobile, Profile = new UserProfile { UserName = item.UserName, NickName = null, HeadUrl = null }, ChannelIn = nameof(ChannelIn.None), UserCategoryIn = nameof(UserCategory.Tuhu), }); createResult.ThrowIfException(true); user = createResult.Result; } } catch (Exception ex) { Logger.Error("用户创建失败。" + ex.Message, ex); } } //添加到待审核集合中 if (!noRepeatList.Contains(item.CarNum) && !noRepeatList.Contains(item.Mobile) && !noRepeatList.Contains(item.DriverNum)) { list.Add(item); noRepeatList.AddRange(new[] { item.Mobile, item.CarNum, item.DriverNum }); } //从SortedSet中移除 var removeResult = await client .RemoveOneUserApplyActivitySortedSetCacheAsync(item); if (!removeResult.Success) { Logger.Error(removeResult.ErrorMessage, removeResult.Exception); } item.UserId = user.UserId; } else { Logger.Error(isExist.ErrorMessage, isExist.Exception); } } } } } } if (list.Any()) { await WashCarActivityMinHangAutoAuditAsync(list); } list.Clear(); noRepeatList.Clear(); } catch (Exception ex) { Logger.Error(ex.Message, ex); } }