Beispiel #1
0
        public Return DetailedBatch(Fortun forModel)
        {
            var resultReturn = new Return();

            try
            {
                //订单ID为空
                if (forModel.OrderId == Guid.Empty)
                {
                    resultReturn.ReturnCode.Code = 2887;
                    return(resultReturn);
                }

                var orderInfo = OrderService.GetByOrderId(forModel.OrderId.ToString());

                if (orderInfo.OrderType != (int)BusinessTypeEnum.DetailedBatch)
                {
                    resultReturn.ReturnCode.Code = 2885;
                    return(resultReturn);
                }

                var dic = GetHtml(orderInfo.OrderType, orderInfo.OrderSearch);

                //若未支付只显示前200个字符
                if (orderInfo.PayState != GlobalConst.TruePaid || orderInfo.PayState != GlobalConst.Paid)
                {
                    var text = dic.Values.ElementAt(1).ToString();

                    //var regex = new Regex(@"^[\u4e00-\u9fa5]|^[\p{P}]|[a-zA-Z]|[<>=;&"" ]", RegexOptions.CultureInvariant);
                    var regex      = new Regex(@"[^\u4e00-\u9fa5,.,。]", RegexOptions.CultureInvariant);
                    var handleText = regex.Replace(text, ""); //过滤非中文

                    if (handleText.Length > 250)
                    {
                        handleText = handleText.Substring(0, 250) + ".....";
                    }

                    var rDetailedBatch = ModelTransfer.Mapper(orderInfo.OrderSearch, new RdetailedBatch());
                    var dic2           = new Dictionary <string, object>
                    {
                        { "SearchInfo", rDetailedBatch },
                        { "PartInfo", handleText }
                    };

                    resultReturn.Content = dic2;
                }
                else
                {
                    resultReturn.Content = dic;
                }

                return(resultReturn);
            }
            catch (Exception ex)
            {
                LogService.InsertLog(ex);
                resultReturn.SetWrong();
                return(resultReturn);
            }
        }
Beispiel #2
0
        public Return BabyName(Fortun forModel)
        {
            var resultReturn = new Return();

            try
            {
                //订单ID为空
                if (forModel.OrderId == Guid.Empty)
                {
                    resultReturn.ReturnCode.Code = 2887;
                    return(resultReturn);
                }

                var orderInfo = OrderService.GetByOrderId(forModel.OrderId.ToString());

                if (orderInfo.OrderType != (int)BusinessTypeEnum.BabyName)
                {
                    resultReturn.ReturnCode.Code = 2885;
                    return(resultReturn);
                }

                var dic            = new Dictionary <string, object>();
                var babyNameResult = BabyNameService.GetByOrderId(forModel.OrderId.ToString());

                //var personalInfo = babyNameResult?.PersonalInfo?.Trim();
                //var nameStr = babyNameResult?.NameList?.Trim();

                dic = GetHtml(orderInfo.OrderType, orderInfo.OrderSearch);
                var dicNameList = ((List <string>)dic["SuggestName"]);
                var nameListStr = string.Empty;
                foreach (var d in dicNameList)
                {
                    nameListStr += d + "|";
                }

                try
                {
                    BabyNameService.Insert(forModel.OrderId.ToString(), dic["PersonalInfo"].ToString(), nameListStr);
                }
                catch (Exception)
                {
                    //IGNORE
                }


                //若未支付只显示前200个字符
                if (orderInfo.PayState != GlobalConst.TruePaid || orderInfo.PayState != GlobalConst.Paid)
                {
                    var nameListPart = ((List <string>)dic["SuggestName"]).Take(12).ToList();
                    var rBabyName    = ModelTransfer.Mapper(orderInfo.OrderSearch, new RbabyName());
                    var dic2         = new Dictionary <string, object>
                    {
                        { "SearchInfo", rBabyName },
                        { "PartInfo", nameListPart }
                    };

                    resultReturn.Content = dic2;
                }
                else
                {
                    resultReturn.Content = dic;
                }

                return(resultReturn);
            }
            catch (Exception ex)
            {
                LogService.InsertLog(ex);
                resultReturn.SetWrong();
                return(resultReturn);
            }
        }
Beispiel #3
0
        public Return ReMasterNameList(Fortun forModel)
        {
            var resultReturn = new Return();

            try
            {
                //订单ID为空
                if (forModel.OrderId == Guid.Empty)
                {
                    resultReturn.ReturnCode.Code = 2887;
                    return(resultReturn);
                }

                var orderInfo = OrderService.GetByOrderId(forModel.OrderId.ToString());

                if (orderInfo.OrderType != (int)BusinessTypeEnum.MasterName)
                {
                    resultReturn.ReturnCode.Code = 2885;
                    return(resultReturn);
                }

                //未支付不允许调用此接口
                if (orderInfo.PayState == GlobalConst.WaitPay)
                {
                    resultReturn.ReturnCode.Code = 2884;
                    return(resultReturn);
                }

                var number = MasterNameService.GetNumberByOrderId(forModel.OrderId.ToString());

                //重复取名次数超出上限
                //因为第一次获取会自动获取第二页数据,所以这里是大于不是大于等于。不然就不能获取四页数据
                if (number > (int)MasterNameListEnum.Number)
                {
                    resultReturn.ReturnCode.Code = 2883;
                    return(resultReturn);
                }

                //只有获取一次以上才能使用该接口
                if (number <= 0)
                {
                    resultReturn.ReturnCode.Code = 2882;
                    return(resultReturn);
                }

                //将数据库存储的最新的数据返回
                var returnNameList = MasterNameService.GetByOrderIdAndNumber(forModel.OrderId.ToString(), number)?.NameList;
                var resultDic      = new Dictionary <string, object>
                {
                    {
                        number.ToString(), new Dictionary <string, object>
                        {
                            { "Number", number },
                            { "NameList", returnNameList?.Split('|').ToList() }
                        }
                    }
                };

                var hasNext = false;

                if (number < (int)MasterNameListEnum.Number)
                {
                    var dic = GetHtml(orderInfo.OrderType, orderInfo.OrderSearch, number + 1);

                    var dicNameList =
                        (List <string>)(((Dictionary <string, object>)dic.Values.ElementAt(0)).Values.ElementAt(1));

                    //当存在姓名列表才记录在数据库中
                    if (dicNameList != null && dicNameList.Count != 0)
                    {
                        var nameListStr = string.Empty;
                        foreach (var d in dicNameList)
                        {
                            nameListStr += d + "|";
                        }

                        MasterNameService.Insert(forModel.OrderId.ToString(), nameListStr, number + 1);

                        if (number != (int)MasterNameListEnum.Number)
                        {
                            hasNext = true;
                        }
                    }
                }

                resultDic.Add("HasNext", hasNext);

                resultReturn.Content = resultDic;

                return(resultReturn);
            }
            catch (Exception ex)
            {
                LogService.InsertLog(ex);
                resultReturn.SetWrong();
                return(resultReturn);
            }
        }
Beispiel #4
0
        public Return MasterNameList(Fortun forModel)
        {
            var resultReturn = new Return();

            try
            {
                //订单ID为空
                if (forModel.OrderId == Guid.Empty)
                {
                    resultReturn.ReturnCode.Code = 2887;
                    return(resultReturn);
                }

                var orderInfo = OrderService.GetByOrderId(forModel.OrderId.ToString());

                if (orderInfo.OrderType != (int)BusinessTypeEnum.MasterName)
                {
                    resultReturn.ReturnCode.Code = 2885;
                    return(resultReturn);
                }

                var dic      = new Dictionary <string, object>();
                var haveNext = false;

                var masterNameResultArr = MasterNameService.GetByOrderId(forModel.OrderId.ToString());

                //若数据中有数据,则不爬取数据;反之爬取
                if (masterNameResultArr.Length > 0)
                {
                    var length = masterNameResultArr.Length;

                    if (masterNameResultArr.Length < (int)MasterNameListEnum.Number)
                    {
                        length = masterNameResultArr.Length - 1;
                    }

                    for (var i = 0; i < length; i++)
                    {
                        var nameStrList = masterNameResultArr[i].NameList?.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries).ToList();

                        dic.Add(masterNameResultArr[i].Number.ToString(CultureInfo.InvariantCulture),
                                new Dictionary <string, object>
                        {
                            { "Number", masterNameResultArr[i].Number },
                            { "NameList", nameStrList }
                        });
                    }

                    if (length != (int)MasterNameListEnum.Number)
                    {
                        var dic3         = GetHtml(orderInfo.OrderType, orderInfo.OrderSearch, length + 1);
                        var dicNameList3 = (List <string>)(((Dictionary <string, object>)dic3.Values.ElementAt(0)).Values.ElementAt(1));

                        if (dicNameList3.Count > 0)
                        {
                            haveNext = true;
                        }
                    }
                }
                else
                {
                    dic = GetHtml(orderInfo.OrderType, orderInfo.OrderSearch);

                    var dicNameList = (List <string>)(((Dictionary <string, object>)dic.Values.ElementAt(0)).Values.ElementAt(1));
                    var nameListStr = string.Empty;
                    foreach (var d in dicNameList)
                    {
                        nameListStr += d + "|";
                    }

                    MasterNameService.Insert(forModel.OrderId.ToString(), nameListStr, 1);

                    #region 自动获取第二页数据

                    var dic2         = GetHtml(orderInfo.OrderType, orderInfo.OrderSearch, 2);
                    var dicNameList2 = (List <string>)(((Dictionary <string, object>)dic2.Values.ElementAt(0)).Values.ElementAt(1));

                    if (dicNameList2.Count > 0)
                    {
                        haveNext = true;
                    }

                    var nameListStr2 = string.Empty;
                    foreach (var d in dicNameList2)
                    {
                        nameListStr2 += d + "|";
                    }

                    MasterNameService.Insert(forModel.OrderId.ToString(), nameListStr2, 2);

                    #endregion
                }

                //若未支付只显示12个推荐姓名
                if (orderInfo.PayState != GlobalConst.TruePaid || orderInfo.PayState != GlobalConst.Paid)
                {
                    var nameListPart = ((List <string>)(((Dictionary <string, object>)dic.Values.ElementAt(0)).Values.ElementAt(1))).Take(12);
                    var rMasterName  = ModelTransfer.Mapper(orderInfo.OrderSearch, new RmasterName());
                    var dic2         = new Dictionary <string, object>
                    {
                        { "SearchInfo", rMasterName },
                        { "PartInfo", nameListPart }
                    };
                    resultReturn.Content = dic2;
                }
                else
                {
                    dic.Add("HasNext", haveNext);
                    resultReturn.Content = dic;
                }

                return(resultReturn);
            }
            catch (Exception ex)
            {
                LogService.InsertLog(ex);
                resultReturn.SetWrong();
                return(resultReturn);
            }
        }