コード例 #1
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, "审核失败"));
        }
コード例 #2
0
        private async Task WashCarActivityMinHangAutoAuditAsync(List <UserApplyActivityModel> userApplyActivityModels,
                                                                int batchInsertCount = 2)
        {
            try
            {
                var list           = new List <UserApplyActivityModel>();
                var serviceCodeDic = new Dictionary <string, Guid>();
                using (var ht = new HttpClient())
                {
                    ht.DefaultRequestHeaders.Add("Authorization", "APPCODE " + "4aca04217e154a2487d5f595e749a28f");
                    foreach (var model in userApplyActivityModels)
                    {
                        if (model.DriverNum.StartsWith("310112") && model.CarNum.StartsWith("沪") &&
                            !model.CarNum.ToLower().Contains("沪c")) //闵行区自动审核通过
                        {
                            if (await CheckApplyUserCountAsync(model.ActivityId))
                            {
                                var serviceCode = Guid.NewGuid();
                                model.Region      = "上海市,闵行区";
                                model.Status      = AuditStatus.Passed;
                                model.ServiceCode = serviceCode;
                                list.Add(model);
                                serviceCodeDic[model.Mobile] = serviceCode;//
                            }
                        }
                        else
                        {
                            var url     = $"http://idquery.market.alicloudapi.com/idcard/query?number={model.DriverNum}";
                            var jsonStr = await ht.GetStringAsync(url);

                            dynamic jObject = JObject.Parse(jsonStr);
                            model.Status = AuditStatus.Pending;
                            if (jObject.ret == "200")
                            {
                                model.Region = $"{jObject.data.prov},{jObject.data.city},{jObject.data.region}";
                                list.Add(model);
                            }
                            else
                            {
                                model.Region = "未知";
                                list.Add(model);
                            }
                        }
                    }
                }
                var sb = new StringBuilder();
                int singleInsertCount = batchInsertCount;
                var count             = Math.Ceiling(list.Count * 1.0f / singleInsertCount);
                for (int i = 0; i < count; i++)
                {
                    var currentList = list.Skip(i * singleInsertCount).Take(singleInsertCount);
                    foreach (var item in currentList)
                    {
                        sb.Append($@"INSERT INTO Activity..T_UserApplyActivity
                                    (
                                        UserId,
                                        ActivityId,
                                        Mobile,
                                        CarNum,
                                        DriverNum,
                                        Ip,
                                        Region,
                                        Status,
                                        Remark,
                                        ServiceCode,
                                        ExpirationTime,
                                        CreatedDateTime,
                                        UpdatedDateTime
                                    )
                                    VALUES
                                    (   '{item.UserId}',      
                                        '{item.ActivityId}',      
                                        N'{item.Mobile}',       
                                        N'{item.CarNum}',       
                                        N'{item.DriverNum}',       
                                        N'{item.Ip}',       
                                        N'{item.Region}',       
                                        {(int)item.Status},         
                                        N'{item.Remark}',       
                                        '{item.ServiceCode}',      
                                        NULL, 
                                        GETDATE(), 
                                        GETDATE()  
                                        );");
                    }
                    //批量插入数据
                    await DbHelper.ExecuteNonQueryAsync(sb.ToString(), CommandType.Text);

                    sb.Clear();
                }

                foreach (var dic in serviceCodeDic)
                {
                    //发送通知短信
                    using (var client = new Service.Utility.SmsClient())
                    {
                        client.SendSms(dic.Key, 138, dic.Value.ToString());
                    }
                }
                list.Clear();
                serviceCodeDic.Clear();
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message, ex);
            }
        }