コード例 #1
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public async Task <int> LoginAsync(string userName, string password, CancellationToken calToken = default)
        {
            var model = new LoginModel
            {
                UserName = userName,
                Password = password,
                //AppId = _operatingSystemVersionProvider.GetDeviceId()
            };

            var result = new APIResult <UserAuthenticationModel>();

            try
            {
                var api = RefitServiceBuilder.Build <IAuthenticationApi>(URL, false);
                result = await _makeRequest.Start(api.LoginAsync(model, calToken), calToken);

                if (result != null)
                {
                    if (result != null && result.Code == 1)
                    {
                        var data = result?.Data;
                        Settings.Password     = password;
                        Settings.UserName     = userName;
                        Settings.AccessToken  = data?.AccessToken;
                        Settings.UUID         = data?.AppId;
                        Settings.UserId       = data?.Id ?? 0;
                        Settings.StoreId      = data?.StoreId ?? 0;
                        Settings.UserMobile   = data?.MobileNumber;
                        Settings.StoreName    = data?.StoreName;
                        Settings.UserRealName = data?.UserRealName;
                        Settings.FaceImage    = data?.FaceImage;
                        Settings.UserEmall    = data?.Email;

                        Settings.DealerNumber           = data?.DealerNumber;
                        Settings.MarketingCenter        = data?.MarketingCenter;
                        Settings.MarketingCenterCode    = data?.MarketingCenterCode;
                        Settings.SalesArea              = data?.SalesArea;
                        Settings.SalesAreaCode          = data?.SalesAreaCode;
                        Settings.BusinessDepartment     = data?.BusinessDepartment;
                        Settings.BusinessDepartmentCode = data?.BusinessDepartmentCode;

                        //Roles
                        if (result.Data.Roles != null && result.Data.Roles.Count > 0)
                        {
                            try
                            {
                                var roles = result.Data.Roles;
                                //用户角色
                                Settings.DefaultRole        = roles.FirstOrDefault()?.Name;
                                Settings.AvailableUserRoles = JsonConvert.SerializeObject(roles);
                                //用户权限
                                Settings.AvailablePermissionRecords = JsonConvert.SerializeObject(result.Data.PermissionRecords);
                            }
                            catch (Exception ex)
                            {
                                result.Message = $"{ex.Message}";
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                e.HandleException();
            }

            return(result.Code);
        }
コード例 #2
0
        /// <summary>
        /// 本地查询
        /// </summary>
        /// <param name="searchStr"></param>
        /// <param name="districtId"></param>
        /// <param name="channelId"></param>
        /// <param name="rankId"></param>
        /// <param name="lineId"></param>
        /// <param name="businessUserId"></param>
        /// <param name="status"></param>
        /// <param name="lat"></param>
        /// <param name="lng"></param>
        /// <param name="range"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public async Task <Tuple <int, IList <TerminalModel> > > SearchTerminals(string searchStr = "", int?districtId = 0, int?channelId = 0, int?rankId = 0, int?lineId = 0, int?businessUserId = 0, bool status = true, int distanceOrderBy = 0, double lat = 0, double lng = 0, double range = 1.5, int pageIndex = 0, int pageSize = 20)
        {
            try
            {
                var results = new APIResult <IList <TerminalModel> >();

                if (range == 0)
                {
                    results = await GetTerminalsAsync(
                        searchStr,
                        districtId,
                        channelId,
                        rankId,
                        businessUserId,
                        lineId,
                        status,
                        pageIndex,
                        pageSize,
                        new CancellationToken());
                }
                else
                {
                    results = await GetRealTimeTerminalsAsync(searchStr,
                                                              districtId,
                                                              channelId,
                                                              rankId,
                                                              businessUserId,
                                                              lineId,
                                                              status,
                                                              pageIndex,
                                                              pageSize,
                                                              range,
                                                              new CancellationToken());
                }

                var pending = new List <TerminalModel>();

                if (results?.Data != null && results?.Code >= 0)
                {
                    pending = results?.Data.ToList();

                    if (distanceOrderBy > 0)
                    {
                        if (distanceOrderBy == 1)
                        {
                            pending = pending.OrderBy(s => s.Distance).ToList();
                        }
                        else if (distanceOrderBy == 2)
                        {
                            pending = pending.OrderByDescending(s => s.Distance).ToList();
                        }
                    }

                    pending = pending.DistinctBy(p => p.Id).ToList();

                    //匹配加工
                    foreach (var s in pending)
                    {
                        if (!string.IsNullOrEmpty(s.DoorwayPhoto))
                        {
                            s.DoorwayPhoto = s.DoorwayPhoto.StartsWith("http") ? s.DoorwayPhoto : "profile_placeholder.png";
                        }
                        else
                        {
                            s.DoorwayPhoto = "profile_placeholder.png";
                        }
                        s.IsNewAdd = DateTime.Now.Subtract(s.CreatedOnUtc).Days < 3;

                        s.RankName = string.IsNullOrEmpty(s.RankName) ? "A级" : s.RankName;

                        if (s.RankName.Contains("a") || s.RankName.Contains("A"))
                        {
                            s.RankName  = "A级";
                            s.RankColor = "#4a89dc";
                        }
                        else if (s.RankName.Contains("b") || s.RankName.Contains("B"))
                        {
                            s.RankName  = "B级";
                            s.RankColor = "#626262";
                        }
                        else if (s.RankName.Contains("c") || s.RankName.Contains("C"))
                        {
                            s.RankName  = "C级";
                            s.RankColor = "#53a245";
                        }
                        else if (s.RankName.Contains("d") || s.RankName.Contains("D"))
                        {
                            s.RankName  = "D级";
                            s.RankColor = "#8942dc";
                        }

                        s.TodayIsVisit = await CheckVisitStore(s);

                        s.BossCall = string.IsNullOrEmpty(s.BossCall) ? "" : s.BossCall;
                        s.Address  = string.IsNullOrEmpty(s.Address) ? "" : s.Address;
                        s.LastSigninDateTimeName = string.IsNullOrEmpty(s.LastSigninDateTimeName) ? "" : s.LastSigninDateTimeName;
                        s.RankName = string.IsNullOrEmpty(s.RankName) ? "" : s.RankName;
                    }
                }

                return(new Tuple <int, IList <TerminalModel> >(results?.Rows ?? 0, pending));
            }
            catch (Exception)
            {
                return(new Tuple <int, IList <TerminalModel> >(0, new List <TerminalModel>()));
            }
        }