public IActionResult AppContectList(ContactRequstPaload payload)
        {
            var response = ResponseModelFactory.CreateResultInstance;

            using (_dbContext)
            {
                var query = from cp in _dbContext.ContactPerson
                            where cp.IsDelete == 0
                            select new
                {
                    cp.Id,
                    cp.ContactName,
                    cp.ContactPersonUuid,
                    cp.Phone,
                    cp.ClientUu.ClientManager,
                    cp.ClientUu.ClientName,
                };
                // 如果是我们指定的角色,可以查看所有的联系人,否则只能看自己负责的客户的联系人
                if (AuthContextService.CurrentUser.RoleName != "超级管理员" && AuthContextService.CurrentUser.RoleName != "行业经理")
                {
                    query = query.Where(x => x.ClientManager == AuthContextService.CurrentUser.Guid);
                }
                //如果联系人名字搜索框不为空,模糊匹配搜索框内容
                if (!string.IsNullOrEmpty(payload.Kk1))
                {
                    query = query.Where(x => x.ContactName.Contains(payload.Kk1));
                }
                //按照ID排序(降序)
                query = query.OrderByDescending(x => x.Id);
                var    qu     = query.ToList();
                string param2 = "{\"code\":0,\"message\":\"成功\",\"ListData\":[";
                //var strlist = query.ToList();
                for (int i = 0; i < qu.Count; i++)
                {
                    var phonelist = "";
                    if (qu[i].Phone != "")
                    {
                        string[] lists = qu[i].Phone.Split(' ');
                        if (lists.Length > 0)
                        {
                            for (int i1 = 0; i1 < lists.Length; i1++)
                            {
                                if (lists[i1] != "")
                                {
                                    if (phonelist != "")
                                    {
                                        phonelist += ",\"" + lists[i1] + "\"";
                                    }
                                    else
                                    {
                                        phonelist = "\"" + lists[i1] + "\"";
                                    }
                                }
                            }
                        }
                    }
                    if (i == 0)
                    {
                        param2 += "{ \"Id\": \"" + qu[i].Id + "\",\"ContactName\":\"" + qu[i].ContactName + "\",\"ContactPersonUuid\":\"" + qu[i].ContactPersonUuid + "\",\"ClientName\":\"" + qu[i].ClientName +
                                  "\",\"phone\":[" + phonelist + "]}";
                    }
                    else
                    {
                        param2 += ",{ \"Id\": \"" + qu[i].Id + "\",\"ContactName\":\"" + qu[i].ContactName + "\",\"ContactPersonUuid\":\"" + qu[i].ContactPersonUuid + "\",\"ClientName\":\"" + qu[i].ClientName +
                                  "\",\"phone\":[" + phonelist + "]}";
                    }
                    //phonelist = "";
                }
                param2 += "]}";

                var result = JsonConvert.DeserializeObject <ContactRoot>(param2);
                response.SetData(result);
                return(Ok(response));
            }
        }
Exemplo n.º 2
0
        public IActionResult List(ContactRequstPaload payload)
        {
            using (_dbContext)
            {
                using (_dbContext)
                {
                    //var query = from cp in _dbContext.ContactPerson
                    //            where cp.IsDelete == 0
                    //            select new
                    //            {
                    //                cp.Id,
                    //                cp.ContactName,
                    //                cp.AddTime,
                    //                cp.Call,
                    //                cp.ContactPersonUuid,
                    //                cp.Title,
                    //                cp.Phone,
                    //                cp.Cellphone,
                    //                sex = cp.Sex == "1" ? "男" : cp.Sex == "2" ? "女" : cp.Sex == "3" ? "未知" : "",
                    //                cp.WeChat,
                    //                cp.BgPhone,
                    //                cp.ZjPhone,
                    //                cp.DateBirth,
                    //                cp.TencentQq,
                    //                cp.OfficeAddress,
                    //                cp.FamilyAddress,
                    //                realName = cp.SystemUserUu.RealName,
                    //                cp.ClientUu.ClientUuid,
                    //                cp.ClientUu.ClientName,
                    //                cp.ClientUu.ClientPhone,
                    //                Manager=cp.ClientUu.ClientManager,
                    //                ClientManager = CooM(cp.ClientUuid),
                    //                cp.Remarks,

                    //            };

                    var query = _dbContext.ContactPersonView.Select(x => new
                    {
                        x.Id,
                        x.ContactName,
                        x.AddTime,
                        x.Call,
                        x.IsDelete,
                        x.ContactPersonUuid,
                        x.Title,
                        x.Phone,
                        x.Cellphone,
                        sex = x.Sex == "1" ? "男" : x.Sex == "2" ? "女" : x.Sex == "3" ? "未知" : "",
                        x.WeChat,
                        x.BgPhone,
                        x.ZjPhone,
                        x.DateBirth,
                        x.TencentQq,
                        x.OfficeAddress,
                        x.FamilyAddress,
                        x.RealName,
                        x.ClientUuid,
                        x.ClientName,
                        x.ClientPhone,
                        x.Manager,
                        x.ClientManager,
                        x.Remarks,
                    }).Where(x => x.IsDelete == 0);

                    // TODO:不可以硬编码,下个版本解决
                    // 如果是我们指定的角色,可以查看所有的联系人,否则只能看自己的联系人
                    if (AuthContextService.CurrentUser.RoleName != "超级管理员" && AuthContextService.CurrentUser.RoleName != "行业经理")
                    {
                        query = query.Where(x => x.Manager == AuthContextService.CurrentUser.Guid);
                    }

                    if (!string.IsNullOrEmpty(payload.Kw))
                    {
                        query = query.Where(x => x.ContactName.Contains(payload.Kw));
                    }

                    if (!string.IsNullOrEmpty(payload.Kw1))
                    {
                        query = query.Where(x => x.ClientName.Contains(payload.Kw1));
                    }

                    query = query.OrderByDescending(x => x.Id);
                    var list       = query.Paged(payload.CurrentPage, payload.PageSize).ToList();
                    var totalCount = query.Count();
                    var response   = ResponseModelFactory.CreateResultInstance;
                    response.SetData(list, totalCount);
                    return(Ok(response));
                }
            }
        }