예제 #1
0
        /// <summary>
        /// Ctor
        /// </summary>
        protected BaseController()
        {
            //CustomerService = Singleton<CustomerService>.Instance;
            //SmsService = Singleton<SmsService>.Instance;
            //AndroidService = Singleton<AndroidService>.Instance;
            //OrderService = Singleton<OrderService>.Instance;
            //OrderSearchService = Singleton<OrderSearchService>.Instance;
            //BusinessTypeService = Singleton<BusinessTypeService>.Instance;

            CustomerService     = new CustomerService();
            SmsService          = new SmsService();
            AndroidService      = new AndroidService();
            OrderService        = new OrderService();
            OrderSearchService  = new OrderSearchService();
            BusinessTypeService = new BusinessTypeService();
            BabyNameService     = new BabyNameService();
            MasterNameService   = new MasterNameService();
        }
예제 #2
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);
            }
        }
예제 #3
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);
            }
        }