using Mall.CacheManager.AppletWeChat;
using Mall.CacheManager.DataStatistic;
using Mall.Common;
using Mall.Common.Enum;
using Mall.Common.Plugin;
using Mall.Model.Entity.TradePavilion;
using Mall.Model.Extend.TradePavilion;
using Mall.Module.TradePavilion;
using Mall.Module.User;
using Mall.Repository.TradePavilion;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using RabbitMQ.Client.Framing.Impl;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using VT.FW.DB;
using static ICSharpCode.SharpZipLib.Zip.ExtendedUnixData;

namespace Mall.Module.TradePavilion
{
    /// <summary>
    /// 宜宾商载通新方法处理类
    /// </summary>
    public partial class BuildingCarrierModule
    {
        /// <summary>
        /// 【商载通】品牌/企业申请仓储层
        /// </summary>
        private readonly RB_BrandEnterpriseApplyForRepository brandEnterpriseApplyForRepository = new RB_BrandEnterpriseApplyForRepository();


        /// <summary>
        /// 【商载通】品牌/企业申请仓储层
        /// </summary>
        private readonly RB_CarrierEnterpriseApplyForRepository carrierEnterpriseApplyForRepository = new RB_CarrierEnterpriseApplyForRepository();

        /// <summary>
        /// 【商载通】地铁申请仓储层
        /// </summary>
        private readonly RB_CarrierEnterpriseMetroApplyForRepository carrierEnterpriseMetroApplyForRepository = new RB_CarrierEnterpriseMetroApplyForRepository();

        /// <summary>
        /// 【商载通】公司仓储层
        /// </summary>
        private readonly RB_CompanyEnterpriseRepository companyEnterpriseRepository = new RB_CompanyEnterpriseRepository();
        /// <summary>
        /// 用户
        /// </summary>
        private readonly Repository.User.RB_Member_UserRepository member_UserRepository = new Repository.User.RB_Member_UserRepository();
        /// <summary>
        /// 企业服务
        /// </summary>
        private readonly RB_EnterpriseServicesApplyRepository enterpriseServicesApplyRepository = new RB_EnterpriseServicesApplyRepository();

        /// <summary>
        /// 楼宇入驻仓储层
        /// </summary>
        private readonly RB_BuildingApplyForRepository buildingApplyForRepository = new RB_BuildingApplyForRepository();


        /// <summary>
        /// 收藏仓储层对象
        /// </summary>
        private readonly RB_CollectRepository collectRepository = new RB_CollectRepository();
        #region 品牌/企业
        /// <summary>
        /// 品牌/企业申请信息列表
        /// </summary>
        /// <param name="query">查询条件</param>
        /// <returns></returns>
        public List<RB_BrandEnterpriseApplyFor_Extend> GetCarrierEnterpriseApplyForModule(RB_BrandEnterpriseApplyFor_Extend query)
        {
            return brandEnterpriseApplyForRepository.GetCarrierEnterpriseApplyForRepository(query);

        }

        /// <summary>
        /// 品牌/企业申请信息列表
        /// </summary>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">每页显示条数</param>
        /// <param name="rowCount">总条数</param>
        /// <param name="query">查询条件</param>
        /// <returns></returns>
        public List<RB_BrandEnterpriseApplyFor_Extend> GetBrandEnterpriseApplyForPageList(int pageIndex, int pageSize, out long rowCount, RB_BrandEnterpriseApplyFor_Extend query)
        {
            var list = brandEnterpriseApplyForRepository.GetBrandEnterpriseApplyForPageList(pageIndex, pageSize, out rowCount, query);

            return list;
        }

        /// <summary>
        /// 根据id获取品牌/企业详情信息
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public RB_BrandEnterpriseApplyFor_Extend GetCarrierEnterpriseApplyForEntity(int ID)
        {

            return brandEnterpriseApplyForRepository.GetEntity(ID).RefMapperTo<RB_BrandEnterpriseApplyFor_Extend>();
        }



        /// <summary>
        ///删除品牌/企业申请信息状态
        /// </summary>
        /// <param name="CompanyId"></param>
        /// <param name="Status"></param>
        /// <returns></returns>
        public bool RemoveBrandEnterpriseApplyForModule(int ID)
        {
            Dictionary<string, object> fileds = new Dictionary<string, object>()
            {
                {nameof(RB_Carrier_Extend.Status), (int)DateStateEnum.Delete},
            };
            bool flag = brandEnterpriseApplyForRepository.Update(fileds, new WhereHelper(nameof(RB_BrandEnterpriseApplyFor_Extend.ID), ID));
            return flag;
        }

        /// <summary>
        /// 新增/修改品牌/企业申请信息
        /// </summary>
        /// <returns></returns>
        public bool SetCarrierEnterpriseApplyFor(RB_BrandEnterpriseApplyFor_Extend model)
        {
            bool flag = false;
            var cmodel = companyEnterpriseRepository.GetEntity(model.CompanyId);
            if (cmodel == null) { return false; }
            if (cmodel.FirstShopType != 1) { return false; }
            //更新认证表  资料状态为完成
            Dictionary<string, object> keyValues = new Dictionary<string, object>()
            {
                { nameof(RB_CompanyEnterprise_Extend.IsComplete),1}
            };
            List<WhereHelper> wheres = new List<WhereHelper>()
            {
                new WhereHelper()
                {
                    FiledName=nameof(RB_CompanyEnterprise_Extend.CompanyId),
                    FiledValue= model.CompanyId,
                    OperatorEnum=OperatorEnum.Equal
                }
            };
            if (model.ID > 0)
            {
                Dictionary<string, object> fileds = new Dictionary<string, object>()
                {
                    {nameof(RB_BrandEnterpriseApplyFor_Extend.UpdateDate),model.UpdateDate },
                    {nameof(RB_BrandEnterpriseApplyFor_Extend.Logo),model.Logo },
                    {nameof(RB_BrandEnterpriseApplyFor_Extend.Banner),model.Banner },
                    {nameof(RB_BrandEnterpriseApplyFor_Extend.VideoUrl),model.VideoUrl },
                    {nameof(RB_BrandEnterpriseApplyFor_Extend.FullBrandName),model.FullBrandName },
                    {nameof(RB_BrandEnterpriseApplyFor_Extend.BrandName),model.BrandName },
                    {nameof(RB_BrandEnterpriseApplyFor_Extend.ShopNum),model.ShopNum },
                    {nameof(RB_BrandEnterpriseApplyFor_Extend.BuiltUpArea),model.BuiltUpArea },
                    {nameof(RB_BrandEnterpriseApplyFor_Extend.EndBuiltUpArea),model.EndBuiltUpArea },
                    {nameof(RB_BrandEnterpriseApplyFor_Extend.BrandType),model.BrandType },
                    {nameof(RB_BrandEnterpriseApplyFor_Extend.CustomerType),model.CustomerType },
                    {nameof(RB_BrandEnterpriseApplyFor_Extend.StoreExpansion),model.StoreExpansion },
                    {nameof(RB_BrandEnterpriseApplyFor_Extend.ProjectType),model.ProjectType },
                    {nameof(RB_BrandEnterpriseApplyFor_Extend.AreaRequirement),model.AreaRequirement },
                    {nameof(RB_BrandEnterpriseApplyFor_Extend.EndAreaRequirement),model.EndAreaRequirement },
                    {nameof(RB_BrandEnterpriseApplyFor_Extend.Advertising),model.Advertising },
                    {nameof(RB_BrandEnterpriseApplyFor_Extend.Other),model.Other },
                    {nameof(RB_BrandEnterpriseApplyFor_Extend.ShopSize),model.ShopSize },
                    {nameof(RB_BrandEnterpriseApplyFor_Extend.Plumbing),model.Plumbing },
                    {nameof(RB_BrandEnterpriseApplyFor_Extend.Caliber),model.Caliber },
                    {nameof(RB_BrandEnterpriseApplyFor_Extend.Sewage),model.Sewage },
                    {nameof(RB_BrandEnterpriseApplyFor_Extend.RanQi),model.RanQi },
                    {nameof(RB_BrandEnterpriseApplyFor_Extend.DianLiang),model.DianLiang },
                    {nameof(RB_BrandEnterpriseApplyFor_Extend.PaiYan),model.PaiYan },
                    {nameof(RB_BrandEnterpriseApplyFor_Extend.KongTiao),model.KongTiao },
                    {nameof(RB_BrandEnterpriseApplyFor_Extend.XinFeng),model.XinFeng },
                    {nameof(RB_BrandEnterpriseApplyFor_Extend.BrandClassId),model.BrandClassId },
                    {nameof(RB_BrandEnterpriseApplyFor_Extend.RanQiBZ),model.RanQiBZ },
                    {nameof(RB_BrandEnterpriseApplyFor_Extend.IsDianLiang),model.IsDianLiang },
                    {nameof(RB_BrandEnterpriseApplyFor_Extend.PaiYanBZ),model. PaiYanBZ },
                    {nameof(RB_BrandEnterpriseApplyFor_Extend.IsShopSize),model.IsShopSize },
                    {nameof(RB_BrandEnterpriseApplyFor_Extend.OpenShopWish),model.OpenShopWish },
                    {nameof(RB_BrandEnterpriseApplyFor_Extend.IsInChengdu),model.IsInChengdu },
                    {nameof(RB_BrandEnterpriseApplyFor_Extend.ExistBrandId),model.ExistBrandId },
                    {nameof(RB_BrandEnterpriseApplyFor_Extend.Introduce),model. Introduce },
                    {nameof(RB_BrandEnterpriseApplyFor_Extend.DevIntention),model.DevIntention },
                    {nameof(RB_BrandEnterpriseApplyFor_Extend.PropertyDemand),model.PropertyDemand },
                    {nameof(RB_BrandEnterpriseApplyFor_Extend.Cooperation),model.Cooperation },
                    {nameof(RB_BrandEnterpriseApplyFor_Extend.Complementary),model.Complementary },
                    {nameof(RB_BrandEnterpriseApplyFor_Extend.ContactName),model.ContactName },
                    {nameof(RB_BrandEnterpriseApplyFor_Extend.ContactPhone),model.ContactPhone },
                };
                flag = brandEnterpriseApplyForRepository.Update(fileds, new WhereHelper(nameof(RB_BrandEnterpriseApplyFor_Extend.ID), model.ID));
            }
            else
            {
                #region 验证品牌数据是否已存在
                var oldList = brandEnterpriseApplyForRepository.GetCarrierEnterpriseApplyForRepository(new RB_BrandEnterpriseApplyFor_Extend() { MallBaseId = model.MallBaseId, CompanyId = model.CompanyId });
                if (oldList != null && oldList.Any())
                {
                    return false;
                }
                #endregion
                flag = brandEnterpriseApplyForRepository.Insert(model) > 0;
                if (flag)
                {
                    if (Config.IsCPSWJAutoExamine == "1")//自动审核
                    {
                        keyValues.Add(nameof(RB_CompanyEnterprise_Extend.CompanyStatus), 1);
                        try
                        {
                            var BrandModel = oldList?.FirstOrDefault();
                            if ((BrandModel?.ExistBrandId ?? 0) > 0)
                            {
                                Dictionary<string, object> filedsBrand = new Dictionary<string, object>()
                                {
                                      { nameof(RB_Brand_Enterprise_Extend.FullBrandName),BrandModel.FullBrandName},
                                      { nameof(RB_Brand_Enterprise_Extend.BrandName),BrandModel.BrandName},
                                      { nameof(RB_Brand_Enterprise_Extend.VideoUrl),BrandModel.VideoUrl},
                                      { nameof(RB_Brand_Enterprise_Extend.Logo),BrandModel.Logo},
                                      { nameof(RB_Brand_Enterprise_Extend.Banner),BrandModel.Banner},
                                      { nameof(RB_Brand_Enterprise_Extend.CategoryId),BrandModel.BrandClassId},
                                      { nameof(RB_Brand_Enterprise_Extend.Introduce),BrandModel.Introduce},
                                      { nameof(RB_Brand_Enterprise_Extend.ShopNum),BrandModel.ShopNum},
                                      { nameof(RB_Brand_Enterprise_Extend.AreaRequirement),BrandModel.ShopNum},
                                      { nameof(RB_Brand_Enterprise_Extend.CustomerType),BrandModel.CustomerType},
                                      { nameof(RB_Brand_Enterprise_Extend.BrandType),BrandModel.BrandType},
                                      { nameof(RB_Brand_Enterprise_Extend.Cooperation),BrandModel.Cooperation},
                                      { nameof(RB_Brand_Enterprise_Extend.PropertyDemand),BrandModel.PropertyDemand},
                                      { nameof(RB_Brand_Enterprise_Extend.Complementary),BrandModel.Complementary},
                                      { nameof(RB_Brand_Enterprise_Extend.ContactName),BrandModel.ContactName},
                                      { nameof(RB_Brand_Enterprise_Extend.ContactPhone),BrandModel.ContactPhone},
                                      { nameof(RB_Brand_Enterprise_Extend.BrandEnterpriseType),BrandModel.BrandEnterpriseType},
                                };
                                brand_EnterpriseRepository.Update(filedsBrand, new WhereHelper(nameof(RB_Brand_Enterprise_Extend.ID), BrandModel.ExistBrandId));
                            }
                            else
                            {
                                #region 新增品牌
                                var inserBModel = model.RefMapperTo<RB_Brand_Enterprise_Extend>();
                                inserBModel.ID = 0;
                                inserBModel.CategoryId = model.BrandClassId;
                                inserBModel.UserId = cmodel.CreateBy;
                                brand_EnterpriseRepository.Insert(inserBModel);
                                #endregion
                            }
                        }
                        catch
                        {
                        }
                    }
                }
            }
            if (flag)
            {  //更新认证表  资料状态为完成
                companyEnterpriseRepository.Update(keyValues, wheres);
            }
            return flag;
        }

        /// <summary>
        /// 新增/修改企业申请信息
        /// </summary>
        /// <returns></returns>
        public bool SetEnterpriseServicesApply(RB_EnterpriseServicesApply_Extend model)
        {
            bool flag = false;
            var cmodel = companyEnterpriseRepository.GetEntity(model.CompanyId);
            if (cmodel == null) { return false; }
            if (cmodel.FirstShopType != 3) { return false; }
            //更新认证表  资料状态为完成
            Dictionary<string, object> keyValues = new Dictionary<string, object>()
            {
                { nameof(RB_CompanyEnterprise_Extend.IsComplete),1}
            };
            List<WhereHelper> wheres = new List<WhereHelper>()
            {
                new WhereHelper()
                {
                    FiledName=nameof(RB_CompanyEnterprise_Extend.CompanyId),
                    FiledValue= model.CompanyId,
                    OperatorEnum=OperatorEnum.Equal
                }
            };
            if (model.ID > 0)
            {
                Dictionary<string, object> fileds = new Dictionary<string, object>()
                {
                    { nameof(RB_EnterpriseServicesApply_Extend.Name),model.Name},
                    { nameof(RB_EnterpriseServicesApply_Extend.Banner),model.Banner},
                    { nameof(RB_EnterpriseServicesApply_Extend.Introduction),model.Introduction},
                    { nameof(RB_EnterpriseServicesApply_Extend.DevIntention),model.DevIntention},
                    { nameof(RB_EnterpriseServicesApply_Extend.Address),model.Address},
                    { nameof(RB_EnterpriseServicesApply_Extend.LatAndLon),model.LatAndLon},
                    { nameof(RB_EnterpriseServicesApply_Extend.OperationTime),model.OperationTime},
                    { nameof(RB_EnterpriseServicesApply_Extend.CategoryId),model.CategoryId},
                    { nameof(RB_EnterpriseServicesApply_Extend.Renovation),model.Renovation},
                    { nameof(RB_EnterpriseServicesApply_Extend.Payment),model.Payment},
                    { nameof(RB_EnterpriseServicesApply_Extend.HandoverDate),model.HandoverDate},
                    { nameof(RB_EnterpriseServicesApply_Extend.IntentionalFloor),model.IntentionalFloor},
                    { nameof(RB_EnterpriseServicesApply_Extend.ElevatorNum),model.ElevatorNum},
                    { nameof(RB_EnterpriseServicesApply_Extend.PropertyFee),model.PropertyFee},
                    { nameof(RB_EnterpriseServicesApply_Extend.RentFee),model.RentFee},
                    { nameof(RB_EnterpriseServicesApply_Extend.ContactName),model.ContactName},
                    { nameof(RB_EnterpriseServicesApply_Extend.ContactPhone),model.ContactPhone},
                    { nameof(RB_EnterpriseServicesApply_Extend.UpdateBy),model.UpdateBy},
                    { nameof(RB_EnterpriseServicesApply_Extend.UpdateDate),model.UpdateDate},
                    { nameof(RB_EnterpriseServicesApply_Extend.EType),model.EType},

                };
                flag = enterpriseServicesApplyRepository.Update(fileds, new WhereHelper(nameof(RB_EnterpriseServicesApply_Extend.ID), model.ID));
            }
            else
            {
                #region 验证企业数据是否已存在
                var oldList = enterpriseServicesApplyRepository.GetEnterpriseServicesApplyRepository(new RB_EnterpriseServicesApply_Extend() { MallBaseId = model.MallBaseId, CompanyId = model.CompanyId });
                if (oldList != null && oldList.Any())
                {
                    return false;
                }
                #endregion
                flag = enterpriseServicesApplyRepository.Insert(model) > 0;
                if (flag)
                {
                    if (Config.IsCPSWJAutoExamine == "1")//自动审核
                    {
                        keyValues.Add(nameof(RB_CompanyEnterprise_Extend.CompanyStatus), 1);
                        try
                        {
                            var BrandModel = oldList?.FirstOrDefault();
                            if ((BrandModel?.ExistServiceId ?? 0) > 0)
                            {
                                Dictionary<string, object> filedsBrand = new Dictionary<string, object>()
                                 {
                                    { nameof(RB_EnterpriseServices.Name),BrandModel.Name},
                                    { nameof(RB_EnterpriseServices.Banner),BrandModel.Banner},
                                    { nameof(RB_EnterpriseServices.Introduction),BrandModel.Introduction},
                                    { nameof(RB_EnterpriseServices.DevIntention),BrandModel.DevIntention},
                                    { nameof(RB_EnterpriseServices.Address),BrandModel.Address},
                                    { nameof(RB_EnterpriseServices.LatAndLon),BrandModel.LatAndLon},
                                    { nameof(RB_EnterpriseServices.OperationTime),BrandModel.OperationTime},
                                    { nameof(RB_EnterpriseServices.CategoryId),BrandModel.CategoryId},
                                    { nameof(RB_EnterpriseServices.Renovation),BrandModel.Renovation},
                                    { nameof(RB_EnterpriseServices.Payment),BrandModel.Payment},
                                    { nameof(RB_EnterpriseServices.HandoverDate),BrandModel.HandoverDate},
                                    { nameof(RB_EnterpriseServices.IntentionalFloor),BrandModel.IntentionalFloor},
                                    { nameof(RB_EnterpriseServices.ElevatorNum),BrandModel.ElevatorNum},
                                    { nameof(RB_EnterpriseServices.PropertyFee),BrandModel.PropertyFee},
                                    { nameof(RB_EnterpriseServices.RentFee),BrandModel.RentFee},
                                    { nameof(RB_EnterpriseServices.ContactName),BrandModel.ContactName},
                                    { nameof(RB_EnterpriseServices.ContactPhone),BrandModel.ContactPhone},
                                    { nameof(RB_EnterpriseServices.UpdateBy),BrandModel.UpdateBy},
                                    { nameof(RB_EnterpriseServices.UpdateDate),BrandModel.UpdateDate},
                                    { nameof(RB_EnterpriseServices.EType),BrandModel.EType},

                                };
                                enterpriseServicesRepository.Update(filedsBrand, new WhereHelper(nameof(RB_EnterpriseServices.ServiceId), BrandModel.ExistServiceId));
                            }
                            else
                            {
                                #region 新增品牌
                                var inserBModel = model.RefMapperTo<RB_EnterpriseServices>();
                                inserBModel.ServiceId = 0;
                                inserBModel.UserId = cmodel.CreateBy;
                                enterpriseServicesRepository.Insert(inserBModel);
                                #endregion
                            }
                        }
                        catch
                        {
                        }
                    }
                }
            }
            if (flag)
            {  //更新认证表  资料状态为完成
                companyEnterpriseRepository.Update(keyValues, wheres);
            }
            return flag;
        }



        /// <summary>
        /// 新增/修改楼宇申请信息
        /// </summary>
        /// <returns></returns>
        public bool SetBuildingApplyFor(RB_BuildingApplyFor_Extend model)
        {
            bool flag = false;
            var cmodel = companyEnterpriseRepository.GetEntity(model.CompanyId);
            if (cmodel == null) { return false; }
            if (cmodel.FirstShopType != 4) { return false; }
            //更新认证表  资料状态为完成
            Dictionary<string, object> keyValues = new Dictionary<string, object>()
            {
                { nameof(RB_CompanyEnterprise_Extend.IsComplete),1}
            };
            List<WhereHelper> wheres = new List<WhereHelper>()
            {
                new WhereHelper()
                {
                    FiledName=nameof(RB_CompanyEnterprise_Extend.CompanyId),
                    FiledValue= model.CompanyId,
                    OperatorEnum=OperatorEnum.Equal
                }
            };
            if (model.ID > 0)
            {
                Dictionary<string, object> fileds = new Dictionary<string, object>()
                {
                    { nameof(RB_BuildingApplyFor_Extend.Name),model.Name},
                    { nameof(RB_BuildingApplyFor_Extend.Name),model.Name},
                    { nameof(RB_BuildingApplyFor_Extend.Banner),model.Banner},
                    { nameof(RB_BuildingApplyFor_Extend.Address),model.Address},
                    { nameof(RB_BuildingApplyFor_Extend.LatAndLon),model.LatAndLon},
                    { nameof(RB_BuildingApplyFor_Extend.OperationTime),model.OperationTime},
                    { nameof(RB_BuildingApplyFor_Extend.CategoryId),model.CategoryId},
                    { nameof(RB_BuildingApplyFor_Extend.Areas),model.Areas},
                    { nameof(RB_BuildingApplyFor_Extend.BuildingNum),model.BuildingNum},
                    { nameof(RB_BuildingApplyFor_Extend.FloorNum),model.FloorNum},
                    { nameof(RB_BuildingApplyFor_Extend.ElevatorNum),model.ElevatorNum},
                    { nameof(RB_BuildingApplyFor_Extend.FloorHeight),model.FloorHeight},
                    { nameof(RB_BuildingApplyFor_Extend.Developers),model.Developers},
                    { nameof(RB_BuildingApplyFor_Extend.PropertyComp),model.PropertyComp},
                    { nameof(RB_BuildingApplyFor_Extend.SaleOrSelf),model.SaleOrSelf},
                    { nameof(RB_BuildingApplyFor_Extend.IsAllOperate),model.IsAllOperate},
                    { nameof(RB_BuildingApplyFor_Extend.ConstructionTime),model.ConstructionTime},
                    { nameof(RB_BuildingApplyFor_Extend.PropertyFee),model.PropertyFee},
                    { nameof(RB_BuildingApplyFor_Extend.RentFee),model.RentFee},
                    { nameof(RB_BuildingApplyFor_Extend.IndustryDirection),model.IndustryDirection},
                    { nameof(RB_BuildingApplyFor_Extend.BrandDemand),model.BrandDemand},
                    { nameof(RB_BuildingApplyFor_Extend.Other),model.Other},
                    { nameof(RB_BuildingApplyFor_Extend.ContactName),model.ContactName},
                    { nameof(RB_BuildingApplyFor_Extend.ContactPhone),model.ContactPhone},
                    { nameof(RB_BuildingApplyFor_Extend.UpdateBy),model.UpdateBy},
                    { nameof(RB_BuildingApplyFor_Extend.UpdateDate),model.UpdateDate},
                };
                flag = buildingApplyForRepository.Update(fileds, new WhereHelper(nameof(RB_BuildingApplyFor_Extend.ID), model.ID));
            }
            else
            {
                #region 验证企业数据是否已存在
                var oldList = buildingApplyForRepository.GetBuildingRepository(new RB_BuildingApplyFor_Extend() { MallBaseId = model.MallBaseId, CompanyId = model.CompanyId });
                if (oldList != null && oldList.Any())
                {
                    return false;
                }
                #endregion
                flag = buildingApplyForRepository.Insert(model) > 0;
                if (flag)
                {
                    if (Config.IsCPSWJAutoExamine == "1")//自动审核
                    {
                        keyValues.Add(nameof(RB_CompanyEnterprise_Extend.CompanyStatus), 1);
                        try
                        {
                            var BrandModel = oldList?.FirstOrDefault();
                            if ((BrandModel?.ExistBuildId ?? 0) > 0)
                            {
                                Dictionary<string, object> filedsBrand = new Dictionary<string, object>()
                                 {
                                   { nameof(RB_Building_Extend.Name),BrandModel.Name},
                                    { nameof(RB_Building_Extend.Banner),BrandModel.Banner},
                                    { nameof(RB_Building_Extend.Address),BrandModel.Address},
                                    { nameof(RB_Building_Extend.LatAndLon),BrandModel.LatAndLon},
                                    { nameof(RB_Building_Extend.OperationTime),BrandModel.OperationTime},
                                    { nameof(RB_Building_Extend.CategoryId),BrandModel.CategoryId},
                                    { nameof(RB_Building_Extend.Areas),BrandModel.Areas},
                                    { nameof(RB_Building_Extend.BuildingNum),BrandModel.BuildingNum},
                                    { nameof(RB_Building_Extend.FloorNum),BrandModel.FloorNum},
                                    { nameof(RB_Building_Extend.ElevatorNum),BrandModel.ElevatorNum},
                                    { nameof(RB_Building_Extend.FloorHeight),BrandModel.FloorHeight},
                                    { nameof(RB_Building_Extend.Developers),BrandModel.Developers},
                                    { nameof(RB_Building_Extend.PropertyComp),BrandModel.PropertyComp},
                                    { nameof(RB_Building_Extend.SaleOrSelf),BrandModel.SaleOrSelf},
                                    { nameof(RB_Building_Extend.IsAllOperate),BrandModel.IsAllOperate},
                                    { nameof(RB_Building_Extend.ConstructionTime),BrandModel.ConstructionTime},
                                    { nameof(RB_Building_Extend.PropertyFee),BrandModel.PropertyFee},
                                    { nameof(RB_Building_Extend.RentFee),BrandModel.RentFee},
                                    { nameof(RB_Building_Extend.IndustryDirection),BrandModel.IndustryDirection},
                                    { nameof(RB_Building_Extend.BrandDemand),BrandModel.BrandDemand},
                                    { nameof(RB_Building_Extend.Other),BrandModel.Other},
                                    { nameof(RB_Building_Extend.ContactName),BrandModel.ContactName},
                                    { nameof(RB_Building_Extend.ContactPhone),BrandModel.ContactPhone},
                                    { nameof(RB_Building_Extend.UpdateBy),BrandModel.UpdateBy},
                                    { nameof(RB_Building_Extend.UpdateDate),BrandModel.UpdateDate},
                                };
                                buildingRepository.Update(filedsBrand, new WhereHelper(nameof(RB_Building_Extend.BuildId), BrandModel.ExistBuildId));
                            }
                            else
                            {
                                #region 新增楼宇
                                var inserBModel = model.RefMapperTo<RB_Building_Extend>();
                                inserBModel.BuildId = 0;
                                inserBModel.UserId = cmodel.CreateBy;
                                buildingRepository.Insert(inserBModel);
                                #endregion
                            }
                        }
                        catch
                        {
                        }
                    }
                }
            }
            if (flag)
            {  //更新认证表  资料状态为完成
                companyEnterpriseRepository.Update(keyValues, wheres);
            }
            return flag;
        }
        #endregion



        #region 载体/楼宇
        /// <summary>
        /// 新增修改载体申请
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool SetCarrierEnterpriseApplyFor(RB_CarrierEnterpriseApplyFor_Extend model)
        {

            bool flag = false;
            var cmodel = companyEnterpriseRepository.GetEntity(model.CompanyId);
            if (cmodel == null) { return false; }

            if (model.ID > 0)
            {
                Dictionary<string, object> fileds = new Dictionary<string, object>()
                {
                    {nameof(RB_CarrierEnterpriseApplyFor_Extend.CarrierName),model.CarrierName },
                    {nameof(RB_CarrierEnterpriseApplyFor_Extend.Logo),model.Logo },
                    {nameof(RB_CarrierEnterpriseApplyFor_Extend.Banner),model.Banner },
                    {nameof(RB_CarrierEnterpriseApplyFor_Extend.VideoUrl),model.VideoUrl },
                    {nameof(RB_CarrierEnterpriseApplyFor_Extend.Address),model.Address },
                    {nameof(RB_CarrierEnterpriseApplyFor_Extend.LatAndLon),model.LatAndLon },
                    {nameof(RB_CarrierEnterpriseApplyFor_Extend.Developers),model.Developers },
                    {nameof(RB_CarrierEnterpriseApplyFor_Extend.OpenTime),model.OpenTime },
                    {nameof(RB_CarrierEnterpriseApplyFor_Extend.CarrierSize),model.CarrierSize },
                    {nameof(RB_CarrierEnterpriseApplyFor_Extend.ProjectType),(int)model.ProjectType },
                    {nameof(RB_CarrierEnterpriseApplyFor_Extend.LayersNum),model.LayersNum },
                    {nameof(RB_CarrierEnterpriseApplyFor_Extend.CarNum),model.CarNum },
                    {nameof(RB_CarrierEnterpriseApplyFor_Extend.CarrierPlan),model.CarrierPlan },
                    {nameof(RB_CarrierEnterpriseApplyFor_Extend.CarrierTarget),model.CarrierTarget },
                    {nameof(RB_CarrierEnterpriseApplyFor_Extend.Location),model.Location },
                    {nameof(RB_CarrierEnterpriseApplyFor_Extend.Crowd),model.Crowd },
                    {nameof(RB_CarrierEnterpriseApplyFor_Extend.ExistCarrierId),model.ExistCarrierId },
                    {nameof(RB_CarrierEnterpriseApplyFor_Extend.Discount),model.Discount },
                    {nameof(RB_CarrierEnterpriseApplyFor_Extend.Honor),model.Honor },
                    {nameof(RB_CarrierEnterpriseApplyFor_Extend.YeJi),model.YeJi },
                    {nameof(RB_CarrierEnterpriseApplyFor_Extend.ShopNum),model.ShopNum },
                    {nameof(RB_CarrierEnterpriseApplyFor_Extend.AreaRequirement ),model.AreaRequirement  },
                    {nameof(RB_CarrierEnterpriseApplyFor_Extend.EndAreaRequirement),model.EndAreaRequirement },
                    {nameof(RB_CarrierEnterpriseApplyFor_Extend.BuiltUpArea),model.BuiltUpArea },
                    {nameof(RB_CarrierEnterpriseApplyFor_Extend.EndBuiltUpArea),model.EndBuiltUpArea },
                    {nameof(RB_CarrierEnterpriseApplyFor_Extend.FirstShopNum),model.FirstShopNum },
                    {nameof(RB_CarrierEnterpriseApplyFor_Extend.StartingInfo),model.StartingInfo },
                    {nameof(RB_CarrierEnterpriseApplyFor_Extend.Ascription),model.Ascription },
                    {nameof(RB_CarrierEnterpriseApplyFor_Extend.PropertyComposition),model.PropertyComposition },
                    {nameof(RB_CarrierEnterpriseApplyFor_Extend.VisitorsFlowrate),model.VisitorsFlowrate },
                    {nameof(RB_CarrierEnterpriseApplyFor_Extend.SupportingFacilities),model.SupportingFacilities },
                    {nameof(RB_CarrierEnterpriseApplyFor_Extend.ManagementCompany),model.ManagementCompany },
                    {nameof(RB_CarrierEnterpriseApplyFor_Extend.BrandDemand),model.BrandDemand },
                    {nameof(RB_CarrierEnterpriseApplyFor_Extend.CategoryId),model.CategoryId },
                    {nameof(RB_CarrierEnterpriseApplyFor_Extend.ContactName),model.ContactName },
                    {nameof(RB_CarrierEnterpriseApplyFor_Extend.ContactPhone),model.ContactPhone },
                };
                flag = carrierEnterpriseApplyForRepository.Update(fileds, new WhereHelper(nameof(RB_CarrierEnterpriseApplyFor_Extend.ID), model.ID));
                if (flag)
                {
                    var oldCarrierMetroList = carrierEnterpriseMetroApplyForRepository.GetCarrierMetroList(new RB_CarrierEnterpriseMetroApplyFor_Extend { TenantId = model.TenantId, MallBaseId = model.MallBaseId, CarrierId = model.ID });
                    carrierEnterpriseMetroApplyForRepository.DeleteBatch(oldCarrierMetroList);
                }
            }
            else
            {
                #region 验证载体申请是否已存在
                var oldList = carrierEnterpriseApplyForRepository.GetCarrierEnterpriseList(new RB_CarrierEnterpriseApplyFor_Extend() { MallBaseId = model.MallBaseId, CompanyId = model.CompanyId });
                if (oldList.Any())
                {
                    return false;
                }
                #endregion
                int Id = carrierEnterpriseApplyForRepository.Insert(model);
                model.ID = Id;
                flag = Id > 0;
            }
            if (flag)
            {
                //更新认证表  资料状态为完成
                Dictionary<string, object> keyValues = new Dictionary<string, object>() 
                {
                     { nameof(RB_CompanyEnterprise_Extend.IsComplete),1}
                };
                List<WhereHelper> wheres = new List<WhereHelper>() 
                {
                    new WhereHelper()
                    {
                        FiledName=nameof(RB_CompanyEnterprise_Extend.CompanyId),
                        FiledValue= model.CompanyId,
                        OperatorEnum=OperatorEnum.Equal
                    }
                 };
                if (Config.IsFirtsShopAutoExamine == "1")//自动审核
                {
                    keyValues.Add(nameof(RB_CompanyEnterprise_Extend.CompanyStatus), 1);
                    //载体
                    var carrierList = carrierEnterpriseApplyForRepository.GetCarrierEnterpriseList(new RB_CarrierEnterpriseApplyFor_Extend() { MallBaseId = cmodel.MallBaseId, CompanyId = cmodel.CompanyId });
                    if (carrierList != null && carrierList.Any())
                    {
                        var CarrierModel = carrierList.FirstOrDefault();
                        var MetroList = carrierEnterpriseMetroApplyForRepository.GetCarrierMetroList(new RB_CarrierEnterpriseMetroApplyFor_Extend { MallBaseId = cmodel.MallBaseId, CarrierId = CarrierModel.ID });

                        if (CarrierModel.ExistCarrierId > 0)
                        {
                            var carrmodel = building_CarrierRepository.GetEntity(CarrierModel.ExistCarrierId);

                            #region 修改载体
                            int FirstStoreTest = 0;
                            if (!string.IsNullOrWhiteSpace(CarrierModel.StartingInfo))
                            {
                                FirstStoreTest = 1;
                            }
                            int OpeningStatus = 0;
                            if (CarrierModel.OpenTime.HasValue)
                            {
                                if (CarrierModel.OpenTime.Value <= System.DateTime.Now)
                                {
                                    OpeningStatus = 1;
                                }
                            }
                            Dictionary<string, object> filedsCarrier = new Dictionary<string, object>()
                            {
                                  {nameof(RB_Building_Carrier_Extend.CarrierName),CarrierModel.CarrierName },
                                  {nameof(RB_Building_Carrier_Extend.Logo),CarrierModel.Logo },
                                  {nameof(RB_Building_Carrier_Extend.Banner),CarrierModel.Banner },
                                  {nameof(RB_Building_Carrier_Extend.Address),CarrierModel.Address },
                                  {nameof(RB_Building_Carrier_Extend.LatAndLon),CarrierModel.LatAndLon },
                                  {nameof(RB_Building_Carrier_Extend.VideoUrl),CarrierModel.VideoUrl },
                                  {nameof(RB_Building_Carrier_Extend.OpeningStatus),CarrierModel },
                                  {nameof(RB_Building_Carrier_Extend.CarrierSize),CarrierModel.CarrierSize },
                                  {nameof(RB_Building_Carrier_Extend.LayersNum),CarrierModel.LayersNum },
                                  {nameof(RB_Building_Carrier_Extend.CarNum),CarrierModel.CarNum },
                                  {nameof(RB_Building_Carrier_Extend.BuiltUpArea),CarrierModel.BuiltUpArea},
                                  {nameof(RB_Building_Carrier_Extend.AreaRequirement),CarrierModel.AreaRequirement},
                                  {nameof(RB_Building_Carrier_Extend.OpenTime),CarrierModel.OpenTime },
                                  {nameof(RB_Building_Carrier_Extend.VisitorsFlowrate),CarrierModel.VisitorsFlowrate },
                                  {nameof(RB_Building_Carrier_Extend.SupportingFacilities),CarrierModel.SupportingFacilities },
                                  {nameof(RB_Building_Carrier_Extend.ManagementCompany),CarrierModel.ManagementCompany },
                                  {nameof(RB_Building_Carrier_Extend.Developers),CarrierModel.Developers },
                                  {nameof(RB_Building_Carrier_Extend.CategoryId),CarrierModel.CategoryId },
                                  {nameof(RB_Building_Carrier_Extend.Ascription),CarrierModel.Ascription },
                                  {nameof(RB_Building_Carrier_Extend.CarrierPlan),CarrierModel.CarrierPlan },
                                  {nameof(RB_Building_Carrier_Extend.BrandDemand),CarrierModel.BrandDemand },
                                  {nameof(RB_Building_Carrier_Extend.Location),CarrierModel.Location },
                                  {nameof(RB_Building_Carrier_Extend.ContactName),CarrierModel.ContactName },
                                  {nameof(RB_Building_Carrier_Extend.ContactPhone),CarrierModel.ContactPhone },
                                  {nameof(RB_Building_Carrier_Extend.BuildingCarrierType),CarrierModel.BuildingCarrierType },
                                  {nameof(RB_Building_Carrier_Extend.UpdateBy),CarrierModel.UpdateBy },
                                  {nameof(RB_Building_Carrier_Extend.UpdateDate),CarrierModel.UpdateDate },
                            };
                            flag = building_CarrierRepository.Update(filedsCarrier, new WhereHelper(nameof(RB_Building_Carrier_Extend.ID), carrmodel.ID));
                            if (flag)
                            {
                                var oldCarrierMetroList = carrierEnterpriseMetroApplyForRepository.GetCarrierMetroList(new RB_CarrierEnterpriseMetroApplyFor_Extend { MallBaseId = CarrierModel.MallBaseId, CarrierId = carrmodel.ID });
                                carrierEnterpriseMetroApplyForRepository.DeleteBatch(oldCarrierMetroList);
                                var mlist = MetroList.RefMapperToList<RB_CarrierEnterpriseMetroApplyFor_Extend>();
                                mlist.ForEach(x =>
                                {
                                    x.ID = 0;
                                    x.CarrierId = carrmodel.ID;
                                    x.Status = 0;
                                    x.TenantId = CarrierModel.TenantId;
                                    x.MallBaseId = CarrierModel.MallBaseId;
                                });
                                carrierEnterpriseMetroApplyForRepository.InsertBatch(mlist);
                            }
                            #endregion
                        }
                        else
                        {
                            #region 新增载体
                            var inserCModel = model.RefMapperTo<RB_Building_Carrier_Extend>();
                            inserCModel.ID = 0;
                            inserCModel.UserId = cmodel.CreateBy;
                            inserCModel.BuiltUpArea = model.BuiltUpArea ?? 0;
                            inserCModel.AreaRequirement = model.AreaRequirement ?? 0;
                            if (model.OpenTime.HasValue)
                            {
                                if (model.OpenTime.Value <= System.DateTime.Now)
                                {
                                    inserCModel.OpeningStatus = 1;
                                }
                                inserCModel.OpenTime = model.OpenTime.Value;
                            }
                            if (!string.IsNullOrWhiteSpace(model.StartingInfo))
                            {
                                inserCModel.FirstStoreTest = 1;
                            }
                            int Id = building_CarrierRepository.Insert(inserCModel);
                            //if (Id > 0)
                            //{
                            //    var mlist = MetroList.RefMapperToList<RB_CarrierEnterpriseMetroApplyFor_Extend>();
                            //    mlist.ForEach(x =>
                            //    {
                            //        x.ID = 0;
                            //        x.CarrierId = Id;
                            //        x.Status = 0;
                            //        x.TenantId = model.TenantId;
                            //        x.MallBaseId = model.MallBaseId;
                            //    });
                            //    carrierEnterpriseMetroApplyForRepository.InsertBatch(mlist);
                            //}
                            #endregion
                        }
                    }
                }
                model.CarrierMetroList.ForEach(x =>
                {
                    x.CarrierId = model.ID;
                    x.Status = 0;
                    x.TenantId = model.TenantId;
                    x.MallBaseId = model.MallBaseId;
                });
                carrierEnterpriseMetroApplyForRepository.InsertBatch(model.CarrierMetroList);
                companyEnterpriseRepository.Update(keyValues, wheres);
            }
            return flag;
        }



        #endregion


        #region 公司

        /// <summary>
        /// 新增修改公司信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int SetCompanyModule(RB_CompanyEnterprise_Extend model)
        {
            int ID;
            if (model.CompanyId > 0)
            {
                ID = model.CompanyId;
                Dictionary<string, object> fileds = new Dictionary<string, object>()
                {
                    {nameof(RB_CompanyEnterprise_Extend.CompanyName),model.CompanyName },
                    {nameof(RB_CompanyEnterprise_Extend.Principal),model.Principal },
                    {nameof(RB_CompanyEnterprise_Extend.Mobile),model.Mobile },
                    {nameof(RB_CompanyEnterprise_Extend.BusinessLicense),model.BusinessLicense },
                    {nameof(RB_CompanyEnterprise_Extend.LegalPerson),model.LegalPerson },
                    {nameof(RB_CompanyEnterprise_Extend.UnifiedCode),model.UnifiedCode },
                    {nameof(RB_CompanyEnterprise_Extend.CompanyIntro),model.CompanyIntro },
                    {nameof(RB_CompanyEnterprise_Extend.FirstShopType),model.FirstShopType },
                    {nameof(RB_CompanyEnterprise_Extend.CompanyStatus),model.CompanyStatus },
                    {nameof(RB_CompanyEnterprise_Extend.UpdateBy),model.UpdateBy },
                    {nameof(RB_CompanyEnterprise_Extend.UpdateDate),model.UpdateDate },
                };
                companyEnterpriseRepository.Update(fileds, new WhereHelper(nameof(RB_CompanyEnterprise_Extend.CompanyId), model.CompanyId));
            }
            else
            {
                var newId = companyEnterpriseRepository.Insert(model);
                model.CompanyId = newId;
                ID = newId;
            }
            return ID;
        }


        /// <summary>
        /// 获取公司信息实体
        /// </summary>
        /// <param name="CompanyId"></param>
        /// <returns></returns>
        public RB_CompanyEnterprise_Extend GetCompanyByUserIdModule(int userId)
        {
            var model = companyEnterpriseRepository.GetCompanyRepository(new RB_CompanyEnterprise_Extend() { CreateBy = userId });
            if (model != null && model.CompanyId > 0)
            {
                model.BrandModel = new RB_BrandEnterpriseApplyFor_Extend();
                model.CarrierModel = new RB_CarrierEnterpriseApplyFor_Extend();
                model.EnterpriseServicesModel = new RB_EnterpriseServicesApply_Extend();
                model.buildingApplyForModel = new RB_BuildingApplyFor_Extend();
                if (model.CompanyStatus == 1)
                {
                    if (model.FirstShopType == 1)
                    {
                        //审核通过了的  直接查询资料表
                        var blist = brand_EnterpriseRepository.GetBrandEnterpriseListRepository(new RB_Brand_Enterprise_Extend() { TenantId = model.TenantId, MallBaseId = model.MallBaseId, UserId = userId });
                        model.BrandModel = blist.FirstOrDefault().RefMapperTo<RB_BrandEnterpriseApplyFor_Extend>();
                        model.BrandModel.BrandClassId = blist?.FirstOrDefault()?.CategoryId??0;
                        model.BrandModel.ClassName = blist?.FirstOrDefault()?.CategoryName??"";
                        if (model.BrandModel != null)
                        {
                            if (!string.IsNullOrWhiteSpace(model.BrandModel.CustomerType))
                            {
                                model.BrandModel.CustomerTypeInfo = new List<string>();
                                foreach (var itemCustomerType in model.BrandModel.CustomerType.Split(","))
                                {
                                    model.BrandModel.CustomerTypeInfo.Add(Common.Plugin.EnumHelper.GetEnumName(itemCustomerType));
                                }
                            }

                            if (!string.IsNullOrWhiteSpace(model.BrandModel.Banner))
                            {
                                model.BrandModel.BannerList = JsonConvert.DeserializeObject<List<string>>(model.BrandModel.Banner);
                            }
                            else
                            {
                                model.BrandModel.BannerList = new List<string>();
                            }
                            if (!string.IsNullOrWhiteSpace(model.BrandModel.PropertyDemand))
                            {
                                model.BrandModel.PropertyDemandList =Common.ConvertHelper.ConvertToListString(model.BrandModel.PropertyDemand);
                            }
                            else
                            {
                                model.BrandModel.PropertyDemandList = new List<string>();
                            }
                        }
                        else
                        {
                            model.BrandModel = new RB_BrandEnterpriseApplyFor_Extend
                            {
                                BannerList = new List<string>(),
                                CustomerTypeInfo = new List<string>(),
                                PropertyDemandList = new List<string>()
                            };
                        }
                    }
                    else if (model.FirstShopType == 2)
                    {
                        var clist = building_CarrierRepository.GetBuildingCarrierListRepository(new RB_Building_Carrier_Extend() { OpeningStatus = -1, TenantId = model.TenantId, MallBaseId = model.MallBaseId, UserId = userId }); ;
                        if (clist.Any())
                        {
                            model.CarrierModel = clist.FirstOrDefault().RefMapperTo<RB_CarrierEnterpriseApplyFor_Extend>();
                            model.CarrierModel.BuiltUpArea = clist.FirstOrDefault()?.BuiltUpArea;
                            model.CarrierModel.AreaRequirement = clist.FirstOrDefault()?.AreaRequirement;
                            model.CarrierModel.OpenTime = clist.FirstOrDefault()?.OpenTime;
                            // model.CarrierModel.BuiltUpArea = clist.FirstOrDefault().BuiltUpArea;
                            //var metroList = carrierEnterpriseMetroApplyForRepository.GetCarrierMetroList(new RB_CarrierEnterpriseMetroApplyFor_Extend { TenantId = model.TenantId, MallBaseId = model.MallBaseId, CarrierId = model.CarrierModel.ID });
                            //model.CarrierModel.CarrierMetroList = new List<RB_CarrierEnterpriseMetroApplyFor_Extend>();
                            //if (metroList != null && metroList.Any())
                            //{
                            //    model.CarrierModel.CarrierMetroList = metroList.RefMapperToList<RB_CarrierEnterpriseMetroApplyFor_Extend>();
                            //}
                            if (!string.IsNullOrWhiteSpace(model.CarrierModel.Banner))
                            {
                                model.CarrierModel.BannerList = JsonConvert.DeserializeObject<List<string>>(model.CarrierModel.Banner);
                            }
                            else
                            {
                                model.CarrierModel.BannerList = new List<string>();
                            }
                        }
                    }
                    else if (model.FirstShopType == 3)
                    {
                        //审核通过了的  直接查询资料表
                        var blist = enterpriseServicesRepository.GetEnterpriseServicesListRepository(new RB_EnterpriseServices_Extend() { TenantId = model.TenantId, MallBaseId = model.MallBaseId, UserId = userId });
                        model.EnterpriseServicesModel = blist.FirstOrDefault().RefMapperTo<RB_EnterpriseServicesApply_Extend>();
                        model.EnterpriseServicesModel.ID = blist.FirstOrDefault().ServiceId;
                        if (model.EnterpriseServicesModel != null)
                        {
                            if (!string.IsNullOrWhiteSpace(model.EnterpriseServicesModel.Banner))
                            {
                                model.EnterpriseServicesModel.BannerList = JsonConvert.DeserializeObject<List<string>>(model.EnterpriseServicesModel.Banner);
                            }
                            else
                            {
                                model.EnterpriseServicesModel.BannerList = new List<string>();
                            }
                        }
                        else
                        {
                            model.EnterpriseServicesModel = new RB_EnterpriseServicesApply_Extend
                            {
                                BannerList = new List<string>(),
                            };
                        }
                    }
                    else if (model.FirstShopType == 4)
                    {
                        //审核通过了的  直接查询资料表
                        var blist = buildingRepository.GetBuildingRepository(new RB_Building_Extend() { TenantId = model.TenantId, MallBaseId = model.MallBaseId, UserId = userId });
                        model.buildingApplyForModel = blist.FirstOrDefault().RefMapperTo<RB_BuildingApplyFor_Extend>();
                        model.buildingApplyForModel.ID = blist.FirstOrDefault().BuildId;
                        if (model.buildingApplyForModel != null)
                        {

                            if (!string.IsNullOrWhiteSpace(model.buildingApplyForModel.Banner))
                            {
                                model.buildingApplyForModel.BannerList = JsonConvert.DeserializeObject<List<string>>(model.buildingApplyForModel.Banner);
                            }
                            else
                            {
                                model.buildingApplyForModel.BannerList = new List<string>();
                            }
                        }
                        else
                        {
                            model.buildingApplyForModel = new RB_BuildingApplyFor_Extend
                            {
                                BannerList = new List<string>(),
                            };
                        }
                    }
                }
                else
                {
                    if (model.FirstShopType == 1)
                    {
                        var brandList = brandEnterpriseApplyForRepository.GetCarrierEnterpriseApplyForRepository(new RB_BrandEnterpriseApplyFor_Extend { TenantId = model.TenantId, MallBaseId = model.MallBaseId, CompanyId = model.CompanyId });
                        if (brandList != null && brandList.Any())
                        {
                            model.BrandModel = brandList.FirstOrDefault();
                            if (model.BrandModel != null)
                            {
                                if (!string.IsNullOrWhiteSpace(model.BrandModel.CustomerType))
                                {
                                    model.BrandModel.CustomerTypeInfo = new List<string>();
                                    foreach (var itemCustomerType in model.BrandModel.CustomerType.Split(","))
                                    {
                                        model.BrandModel.CustomerTypeInfo.Add(Common.Plugin.EnumHelper.GetEnumName(itemCustomerType));
                                    }
                                }
                                if (!string.IsNullOrWhiteSpace(model.BrandModel.Banner))
                                {
                                    model.BrandModel.BannerList = JsonConvert.DeserializeObject<List<string>>(model.BrandModel.Banner);
                                }
                                else
                                {
                                    model.BrandModel.BannerList = new List<string>();
                                }
                                if (!string.IsNullOrWhiteSpace(model.BrandModel.PropertyDemand))
                                {
                                    model.BrandModel.PropertyDemandList = JsonConvert.DeserializeObject<List<string>>(model.BrandModel.PropertyDemand);
                                }
                                else
                                {
                                    model.BrandModel.PropertyDemandList = new List<string>();
                                }
                            }
                            else
                            {
                                model.BrandModel = new RB_BrandEnterpriseApplyFor_Extend
                                {
                                    BannerList = new List<string>(),
                                    CustomerTypeInfo = new List<string>(),
                                    PropertyDemandList = new List<string>(),
                                };
                            }
                        }
                    }
                    else if (model.FirstShopType == 2)
                    {
                        var carrierList = carrierEnterpriseApplyForRepository.GetCarrierEnterpriseList(new RB_CarrierEnterpriseApplyFor_Extend() { TenantId = model.TenantId, MallBaseId = model.MallBaseId, CompanyId = model.CompanyId });
                        if (carrierList.Any())
                        {
                            model.CarrierModel = carrierList.FirstOrDefault();
                            var metroList = carrierEnterpriseMetroApplyForRepository.GetCarrierMetroList(new RB_CarrierEnterpriseMetroApplyFor_Extend { TenantId = model.TenantId, MallBaseId = model.MallBaseId, CarrierId = model.CarrierModel.ID });
                            model.CarrierModel.CarrierMetroList = new List<RB_CarrierEnterpriseMetroApplyFor_Extend>();
                            if (metroList != null && metroList.Any())
                            {
                                model.CarrierModel.CarrierMetroList = metroList;
                            }
                            if (!string.IsNullOrWhiteSpace(model.CarrierModel.Banner))
                            {
                                model.CarrierModel.BannerList = JsonConvert.DeserializeObject<List<string>>(model.CarrierModel.Banner);
                            }
                            else
                            {
                                model.CarrierModel.BannerList = new List<string>();
                            }
                            if (!string.IsNullOrWhiteSpace(model.CarrierModel.Honor))
                            {
                                model.CarrierModel.HonorList = JsonConvert.DeserializeObject<List<string>>(model.CarrierModel.Honor);
                            }
                            else
                            {
                                model.CarrierModel.HonorList = new List<string>();
                            }
                            if (!string.IsNullOrWhiteSpace(model.CarrierModel.FirstShopNum))
                            {
                                model.CarrierModel.FirstShopNumList = JsonConvert.DeserializeObject<List<FirstShopNumModel>>(model.CarrierModel.FirstShopNum);
                            }
                            else
                            {
                                model.CarrierModel.FirstShopNumList = new List<FirstShopNumModel>();
                            }


                        }
                    }
                    else if (model.FirstShopType == 3)
                    {
                        var brandList = enterpriseServicesApplyRepository.GetEnterpriseServicesApplyRepository(new RB_EnterpriseServicesApply_Extend { TenantId = model.TenantId, MallBaseId = model.MallBaseId, CompanyId = model.CompanyId });
                        if (brandList != null && brandList.Any())
                        {
                            model.EnterpriseServicesModel = brandList.FirstOrDefault();
                            if (model.BrandModel != null)
                            {
                                if (!string.IsNullOrWhiteSpace(model.BrandModel.CustomerType))
                                {
                                    model.BrandModel.CustomerTypeInfo = new List<string>();
                                    foreach (var itemCustomerType in model.BrandModel.CustomerType.Split(","))
                                    {
                                        model.BrandModel.CustomerTypeInfo.Add(Common.Plugin.EnumHelper.GetEnumName(itemCustomerType));
                                    }
                                }
                                if (!string.IsNullOrWhiteSpace(model.BrandModel.Banner))
                                {
                                    model.BrandModel.BannerList = JsonConvert.DeserializeObject<List<string>>(model.BrandModel.Banner);
                                }
                                else
                                {
                                    model.BrandModel.BannerList = new List<string>();
                                }
                            }
                            else
                            {
                                model.BrandModel = new RB_BrandEnterpriseApplyFor_Extend
                                {
                                    BannerList = new List<string>(),
                                    CustomerTypeInfo = new List<string>()
                                };
                            }
                        }
                    }
                    else if (model.FirstShopType == 4)
                    {
                        var brandList = buildingApplyForRepository.GetBuildingRepository(new RB_BuildingApplyFor_Extend { TenantId = model.TenantId, MallBaseId = model.MallBaseId, CompanyId = model.CompanyId });
                        if (brandList != null && brandList.Any())
                        {
                            model.buildingApplyForModel = brandList.FirstOrDefault();
                            if (model.BrandModel != null)
                            {
                                if (!string.IsNullOrWhiteSpace(model.BrandModel.CustomerType))
                                {
                                    model.BrandModel.CustomerTypeInfo = new List<string>();
                                    foreach (var itemCustomerType in model.BrandModel.CustomerType.Split(","))
                                    {
                                        model.BrandModel.CustomerTypeInfo.Add(Common.Plugin.EnumHelper.GetEnumName(itemCustomerType));
                                    }
                                }
                                if (!string.IsNullOrWhiteSpace(model.BrandModel.Banner))
                                {
                                    model.BrandModel.BannerList = JsonConvert.DeserializeObject<List<string>>(model.BrandModel.Banner);
                                }
                                else
                                {
                                    model.BrandModel.BannerList = new List<string>();
                                }
                            }
                            else
                            {
                                model.BrandModel = new RB_BrandEnterpriseApplyFor_Extend
                                {
                                    BannerList = new List<string>(),
                                    CustomerTypeInfo = new List<string>()
                                };
                            }
                        }
                    }
                }
            }
            return model;
        }
        /// <summary>
        /// 获取认证状态
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public object GetCommpanyStatus(int userId)
        {
            var model = companyEnterpriseRepository.GetCompanyRepository(new RB_CompanyEnterprise_Extend() { CreateBy = userId });
            if (model != null)
            {
                if (model.CompanyStatus == 1)
                {
                    return new
                    {
                        CompanyStatus = 5,//认证通过
                        model.FirstShopType,
                        model.CompanyName
                    };
                }
                else if (model.CompanyStatus == 0)
                {
                    if (model.IsComplete == 1)
                    {
                        return new
                        {
                            CompanyStatus = 3,//认证审核中
                            model.FirstShopType,
                            model.CompanyName
                        };
                    }
                    else
                    {
                        return new
                        {
                            CompanyStatus = 2,//认证待完善
                            model.FirstShopType,
                            model.CompanyName
                        };
                    }
                }
                else if (model.CompanyStatus == 2)
                {
                    return new
                    {
                        CompanyStatus = 4,//认证未通过
                        model.FirstShopType,
                        model.CompanyName
                    };
                }
            }
            else
            {
                return new
                {
                    CompanyStatus = 1,//未认证
                    FirstShopType = 0,
                    CompanyName = ""
                };
            }
            return model;
        }
        /// <summary>
        /// 获取公司信息分页列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="rowsCount"></param>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_CompanyEnterprise_Extend> GetCompanyEnterprisePageModule(int pageIndex, int pageSize, out long rowsCount, RB_CompanyEnterprise_Extend query)
        {
            var list = companyEnterpriseRepository.GetCompanyEnterprisePageRepository(pageIndex, pageSize, out rowsCount, query);
            if (list != null && list.Any())
            {
                //查询用户列表
                string userIds = string.Join(",", list.Select(x => x.CreateBy));
                var ulist = member_UserRepository.GetList(new Model.Extend.User.RB_Member_User_Extend() { MallBaseId = query.MallBaseId, UserIds = userIds });
                foreach (var item in list)
                {
                    var umodel = ulist.Where(x => x.Id == item.CreateBy).FirstOrDefault();
                    item.UserName = umodel?.Name ?? "";
                    item.UserIcon = umodel?.Photo ?? "";
                }
            }
            return list;
        }


        /// <summary>
        /// 获取公司信息实体
        /// </summary>
        /// <param name="CompanyId"></param>
        /// <returns></returns>
        public RB_CompanyEnterprise_Extend GetCompanyModule(object CompanyId)
        {
            var model = companyEnterpriseRepository.GetEntity<RB_CompanyEnterprise_Extend>(CompanyId);
            if (model != null && model.CompanyId > 0)
            {
                model.BrandModel = new RB_BrandEnterpriseApplyFor_Extend();
                model.CarrierModel = new RB_CarrierEnterpriseApplyFor_Extend();
                model.EnterpriseServicesModel = new RB_EnterpriseServicesApply_Extend();
                model.buildingApplyForModel = new RB_BuildingApplyFor_Extend();
                //品牌
                if (model.FirstShopType == 1)
                {
                    var brandList = brandEnterpriseApplyForRepository.GetCarrierEnterpriseApplyForRepository(new RB_BrandEnterpriseApplyFor_Extend { TenantId = model.TenantId, MallBaseId = model.MallBaseId, CompanyId = model.CompanyId });
                    if (brandList != null && brandList.Any())
                    {
                        model.BrandModel = brandList.FirstOrDefault();
                        if (model.BrandModel != null && !string.IsNullOrWhiteSpace(model.BrandModel.CustomerType))
                        {
                            model.BrandModel.CustomerTypeInfo = new List<string>();
                            foreach (var itemCustomerType in model.BrandModel.CustomerType.Split(","))
                            {
                                model.BrandModel.CustomerTypeInfo.Add(Common.Plugin.EnumHelper.GetEnumName(itemCustomerType));
                            }
                        }

                        if (!string.IsNullOrWhiteSpace(model.BrandModel.Banner))
                        {
                            model.BrandModel.BannerList = JsonConvert.DeserializeObject<List<string>>(model.BrandModel.Banner);
                        }
                        else
                        {
                            model.BrandModel.BannerList = new List<string>();
                        }
                        if (!string.IsNullOrWhiteSpace(model.BrandModel.PropertyDemand))
                        {
                            model.BrandModel.PropertyDemandList = Common.ConvertHelper.ConvertToListString(model.BrandModel.PropertyDemand);
                                //JsonConvert.DeserializeObject<List<string>>(model.BrandModel.PropertyDemand);
                        }
                        else
                        {
                            model.BrandModel.PropertyDemandList = new List<string>();
                        }
                        model.BrandModel.ProjectName = model.BrandModel.ProjectType.GetEnumName();
                    }
                }
                //载体
                else if (model.FirstShopType == 2)
                {
                    var carrierList = carrierEnterpriseApplyForRepository.GetCarrierEnterpriseList(new RB_CarrierEnterpriseApplyFor_Extend() { TenantId = model.TenantId, MallBaseId = model.MallBaseId, CompanyId = model.CompanyId });
                    if (carrierList.Any())
                    {
                        model.CarrierModel = carrierList.FirstOrDefault();
                        var metroList = carrierEnterpriseMetroApplyForRepository.GetCarrierMetroList(new RB_CarrierEnterpriseMetroApplyFor_Extend { TenantId = model.TenantId, MallBaseId = model.MallBaseId, CarrierId = model.CarrierModel.ID });
                        model.CarrierModel.CarrierMetroList = new List<RB_CarrierEnterpriseMetroApplyFor_Extend>();
                        if (metroList != null && metroList.Any())
                        {
                            model.CarrierModel.CarrierMetroList = metroList;
                        }
                        if (!string.IsNullOrWhiteSpace(model.CarrierModel.Banner))
                        {
                            model.CarrierModel.BannerList = JsonConvert.DeserializeObject<List<string>>(model.CarrierModel.Banner);
                        }
                        else
                        {
                            model.CarrierModel.BannerList = new List<string>();
                        }

                        model.CarrierModel.ProjectName = model.CarrierModel.ProjectType.GetEnumName();
                    }
                }
                //企业服务
                else if (model.FirstShopType == 3)
                {
                    var brandList = enterpriseServicesApplyRepository.GetEnterpriseServicesApplyRepository(new RB_EnterpriseServicesApply_Extend { TenantId = model.TenantId, MallBaseId = model.MallBaseId, CompanyId = model.CompanyId });
                    if (brandList != null && brandList.Any())
                    {
                        model.EnterpriseServicesModel = brandList.FirstOrDefault();
                        if (!string.IsNullOrWhiteSpace(model.EnterpriseServicesModel.Banner))
                        {
                            model.EnterpriseServicesModel.BannerList = JsonConvert.DeserializeObject<List<string>>(model.EnterpriseServicesModel.Banner);
                        }
                        else
                        {
                            model.EnterpriseServicesModel.BannerList = new List<string>();
                        }
                    }
                }
                //活力楼宇
                else if (model.FirstShopType == 4)
                {
                    var brandList = buildingApplyForRepository.GetBuildingRepository(new RB_BuildingApplyFor_Extend { TenantId = model.TenantId, MallBaseId = model.MallBaseId, CompanyId = model.CompanyId });
                    if (brandList != null && brandList.Any())
                    {
                        model.buildingApplyForModel = brandList.FirstOrDefault();
                        if (!string.IsNullOrWhiteSpace(model.buildingApplyForModel.Banner))
                        {
                            model.buildingApplyForModel.BannerList = JsonConvert.DeserializeObject<List<string>>(model.buildingApplyForModel.Banner);
                        }
                        else
                        {
                            model.buildingApplyForModel.BannerList = new List<string>();
                        }
                    }
                }
            }
            return model;
        }


        /// <summary>
        /// 更新公司信息状态
        /// </summary>
        /// <param name="CompanyId"></param>
        /// <param name="Status"></param>
        /// <returns></returns>
        public bool RemoveCompanyModule(int CompanyId, int Status)
        {
            Dictionary<string, object> fileds = new Dictionary<string, object>()
            {
                {nameof(RB_CompanyEnterprise_Extend.Status),Status },
            };
            bool flag = companyEnterpriseRepository.Update(fileds, new WhereHelper(nameof(RB_CompanyEnterprise_Extend.CompanyId), CompanyId));
            return flag;
        }

        /// <summary>
        /// 获取公司信息实体
        /// </summary>
        /// <param name="CompanyId"></param>
        /// <returns></returns>
        public RB_CompanyEnterprise_Extend GetCompanyEntity(object CompanyId)
        {
            var model = companyEnterpriseRepository.GetEntity<RB_CompanyEnterprise_Extend>(CompanyId);

            return model;
        }


        /// <summary>
        /// 更新公司审核状态
        /// </summary>
        /// <param name="CompanyId"></param>
        /// <param name="Status"></param>
        /// <param name="remark"></param>
        /// <returns></returns>
        public string UpdateCompanyStatus(int CompanyId, int Status, string remark)
        {
            var trans = companyEnterpriseRepository.DbTransaction;
            try
            {
                Dictionary<string, object> fileds = new Dictionary<string, object>()
                {
                    {nameof(RB_CompanyEnterprise_Extend.CompanyStatus),Status },
                };
                if (Status == 2)
                {
                    fileds.Add(nameof(RB_CompanyEnterprise_Extend.RejectRemark), remark);
                }
                List<WhereHelper> wheres = new List<WhereHelper>()
                {
                     new WhereHelper()
                     {
                         FiledName=nameof(RB_CompanyEnterprise_Extend.CompanyId),
                         FiledValue=CompanyId,
                         OperatorEnum=OperatorEnum.Equal
                     }
                };
                bool flag = companyEnterpriseRepository.Update(fileds, wheres, trans);
                if (flag)
                {
                    //新增 更新品牌 载体信息
                    if (Status == 1)
                    {
                        var cmodel = companyEnterpriseRepository.GetEntity(CompanyId);
                        //消费品牌
                        if (cmodel.FirstShopType == 1)
                        {
                            var brandList = brandEnterpriseApplyForRepository.GetCarrierEnterpriseApplyForRepository(new RB_BrandEnterpriseApplyFor_Extend { MallBaseId = cmodel.MallBaseId, CompanyId = cmodel.CompanyId });
                            if (brandList != null && brandList.Any())
                            {
                                var BrandModel = brandList.FirstOrDefault();
                                var brandEnterpriseModel = new RB_Brand_Enterprise_Extend()
                                {
                                    FullBrandName = BrandModel.FullBrandName,
                                    BrandName = BrandModel.BrandName,
                                    VideoUrl = BrandModel.VideoUrl,
                                    Logo = BrandModel.Logo,
                                    Banner = BrandModel.Banner,
                                    CategoryId = BrandModel.BrandClassId,
                                    Introduce = BrandModel.Introduce,
                                    ShopNum = BrandModel.ShopNum,
                                    AreaRequirement = BrandModel.ShopNum,
                                    CustomerType = BrandModel.CustomerType,
                                    BrandType = BrandModel.BrandType,
                                    Cooperation = BrandModel.Cooperation,
                                    PropertyDemand = BrandModel.PropertyDemand,
                                    Complementary = BrandModel.Complementary,
                                    ContactName = BrandModel.ContactName,
                                    ContactPhone = BrandModel.ContactPhone,
                                    BrandEnterpriseType = BrandModel.BrandEnterpriseType,
                                    TenantId = BrandModel.TenantId,
                                    MallBaseId = BrandModel.MallBaseId,
                                };
                                if (BrandModel.ExistBrandId > 0)
                                {
                                    Dictionary<string, object> filedsBrand = new Dictionary<string, object>()
                                    {
                                        { nameof(RB_Brand_Enterprise_Extend.FullBrandName),brandEnterpriseModel.FullBrandName},
                                        { nameof(RB_Brand_Enterprise_Extend.BrandName),brandEnterpriseModel.BrandName},
                                        { nameof(RB_Brand_Enterprise_Extend.VideoUrl),brandEnterpriseModel.VideoUrl},
                                        { nameof(RB_Brand_Enterprise_Extend.Logo),brandEnterpriseModel.Logo},
                                        { nameof(RB_Brand_Enterprise_Extend.Banner),brandEnterpriseModel.Banner},
                                        { nameof(RB_Brand_Enterprise_Extend.CategoryId),brandEnterpriseModel.BrandClassId},
                                        { nameof(RB_Brand_Enterprise_Extend.Introduce),brandEnterpriseModel.Introduce},
                                        { nameof(RB_Brand_Enterprise_Extend.ShopNum),brandEnterpriseModel.ShopNum},
                                        { nameof(RB_Brand_Enterprise_Extend.AreaRequirement),brandEnterpriseModel.ShopNum},
                                        { nameof(RB_Brand_Enterprise_Extend.CustomerType),brandEnterpriseModel.CustomerType},
                                        { nameof(RB_Brand_Enterprise_Extend.BrandType),brandEnterpriseModel.BrandType},
                                        { nameof(RB_Brand_Enterprise_Extend.Cooperation),brandEnterpriseModel.Cooperation},
                                        { nameof(RB_Brand_Enterprise_Extend.PropertyDemand),brandEnterpriseModel.PropertyDemand},
                                        { nameof(RB_Brand_Enterprise_Extend.Complementary),brandEnterpriseModel.Complementary},
                                        { nameof(RB_Brand_Enterprise_Extend.ContactName),brandEnterpriseModel.ContactName},
                                        { nameof(RB_Brand_Enterprise_Extend.ContactPhone),brandEnterpriseModel.ContactPhone},
                                        { nameof(RB_Brand_Enterprise_Extend.BrandEnterpriseType),brandEnterpriseModel.BrandEnterpriseType},
                                    };
                                    brand_EnterpriseRepository.Update(filedsBrand, new WhereHelper(nameof(RB_Brand_Enterprise_Extend.ID), BrandModel.ExistBrandId), trans);
                                }
                                else
                                {
                                    brandEnterpriseModel.ID = 0;
                                    brandEnterpriseModel.CategoryId = BrandModel.BrandClassId;
                                    brandEnterpriseModel.UserId = cmodel.CreateBy;
                                    brandEnterpriseModel.CreateDate = DateTime.Now;
                                    brand_EnterpriseRepository.Insert(brandEnterpriseModel, trans);
                                }
                            }
                        }
                        //载体
                        else if (cmodel.FirstShopType == 2)
                        {
                            var carrierList = carrierEnterpriseApplyForRepository.GetCarrierEnterpriseList(new RB_CarrierEnterpriseApplyFor_Extend() { MallBaseId = cmodel.MallBaseId, CompanyId = cmodel.CompanyId });
                            if (carrierList != null && carrierList.Any())
                            {
                                var CarrierModel = carrierList.FirstOrDefault();
                                int OpeningStatus = 0;
                                if (CarrierModel.OpenTime.HasValue)
                                {
                                    if (CarrierModel.OpenTime.Value <= System.DateTime.Now)
                                    {
                                        OpeningStatus = 1;
                                    }
                                }
                                var buildingCarrierModel = new RB_Building_Carrier_Extend()
                                {
                                    CarrierName = CarrierModel.CarrierName,
                                    Logo = CarrierModel.Logo,
                                    Banner = CarrierModel.Banner,
                                    Address = CarrierModel.Address,
                                    LatAndLon = CarrierModel.LatAndLon,
                                    VideoUrl = CarrierModel.VideoUrl,
                                    OpeningStatus = OpeningStatus,
                                    CarrierSize = CarrierModel.CarrierSize,
                                    LayersNum = CarrierModel.LayersNum,
                                    CarNum = CarrierModel.CarNum,
                                    BuiltUpArea = CarrierModel?.BuiltUpArea ?? 0,
                                    AreaRequirement = CarrierModel?.AreaRequirement ?? 0,
                                    VisitorsFlowrate = CarrierModel.VisitorsFlowrate,
                                    SupportingFacilities = CarrierModel.SupportingFacilities,
                                    ManagementCompany = CarrierModel.ManagementCompany,
                                    Developers = CarrierModel.Developers,
                                    CategoryId = CarrierModel.CategoryId,
                                    Ascription = CarrierModel.Ascription,
                                    CarrierPlan = CarrierModel.CarrierPlan,
                                    BrandDemand = CarrierModel.BrandDemand,
                                    Location = CarrierModel.Location,
                                    ContactName = CarrierModel.ContactName,
                                    ContactPhone = CarrierModel.ContactPhone,
                                    BuildingCarrierType = CarrierModel.BuildingCarrierType,
                                    UpdateBy = CarrierModel.UpdateBy,
                                    UpdateDate = CarrierModel.UpdateDate,
                                    TenantId = CarrierModel.TenantId,
                                    MallBaseId = CarrierModel.MallBaseId,
                                };
                                if (!string.IsNullOrEmpty(Common.ConvertHelper.FormatDate(CarrierModel?.OpenTime)))
                                {
                                    buildingCarrierModel.OpenTime = Convert.ToDateTime(CarrierModel.OpenTime);
                                }
                                var MetroList = carrierEnterpriseMetroApplyForRepository.GetCarrierMetroList(new RB_CarrierEnterpriseMetroApplyFor_Extend { MallBaseId = cmodel.MallBaseId, CarrierId = CarrierModel.ID });
                                if (CarrierModel.ExistCarrierId > 0)
                                {
                                    //修改
                                    #region 验证品牌是否已关联用户
                                    var carrmodel = building_CarrierRepository.GetEntity(CarrierModel.ExistCarrierId);
                                    #endregion

                                    #region 修改载体
                                    Dictionary<string, object> filedsCarrier = new Dictionary<string, object>()
                                    {
                                        {nameof(RB_Building_Carrier_Extend.CarrierName),buildingCarrierModel.CarrierName },
                                        {nameof(RB_Building_Carrier_Extend.Logo),buildingCarrierModel.Logo },
                                        {nameof(RB_Building_Carrier_Extend.Banner),buildingCarrierModel.Banner },
                                        {nameof(RB_Building_Carrier_Extend.Address),buildingCarrierModel.Address },
                                        {nameof(RB_Building_Carrier_Extend.LatAndLon),buildingCarrierModel.LatAndLon },
                                        {nameof(RB_Building_Carrier_Extend.VideoUrl),buildingCarrierModel.VideoUrl },
                                        {nameof(RB_Building_Carrier_Extend.OpeningStatus),buildingCarrierModel },
                                        {nameof(RB_Building_Carrier_Extend.CarrierSize),buildingCarrierModel.CarrierSize },
                                        {nameof(RB_Building_Carrier_Extend.LayersNum),buildingCarrierModel.LayersNum },
                                        {nameof(RB_Building_Carrier_Extend.CarNum),buildingCarrierModel.CarNum },
                                        {nameof(RB_Building_Carrier_Extend.BuiltUpArea),buildingCarrierModel.BuiltUpArea},
                                        {nameof(RB_Building_Carrier_Extend.AreaRequirement),buildingCarrierModel.AreaRequirement},
                                        {nameof(RB_Building_Carrier_Extend.OpenTime),buildingCarrierModel.OpenTime },
                                        {nameof(RB_Building_Carrier_Extend.VisitorsFlowrate),buildingCarrierModel.VisitorsFlowrate },
                                        {nameof(RB_Building_Carrier_Extend.SupportingFacilities),buildingCarrierModel.SupportingFacilities },
                                        {nameof(RB_Building_Carrier_Extend.ManagementCompany),buildingCarrierModel.ManagementCompany },
                                        {nameof(RB_Building_Carrier_Extend.Developers),buildingCarrierModel.Developers },
                                        {nameof(RB_Building_Carrier_Extend.CategoryId),buildingCarrierModel.CategoryId },
                                        {nameof(RB_Building_Carrier_Extend.Ascription),buildingCarrierModel.Ascription },
                                        {nameof(RB_Building_Carrier_Extend.CarrierPlan),buildingCarrierModel.CarrierPlan },
                                        {nameof(RB_Building_Carrier_Extend.BrandDemand),buildingCarrierModel.BrandDemand },
                                        {nameof(RB_Building_Carrier_Extend.Location),buildingCarrierModel.Location },
                                        {nameof(RB_Building_Carrier_Extend.ContactName),buildingCarrierModel.ContactName },
                                        {nameof(RB_Building_Carrier_Extend.ContactPhone),buildingCarrierModel.ContactPhone },
                                        {nameof(RB_Building_Carrier_Extend.BuildingCarrierType),buildingCarrierModel.BuildingCarrierType },
                                        {nameof(RB_Building_Carrier_Extend.UpdateBy),buildingCarrierModel.UpdateBy },
                                        {nameof(RB_Building_Carrier_Extend.UpdateDate),buildingCarrierModel.UpdateDate },
                                    };
                                    flag = building_CarrierRepository.Update(filedsCarrier, new WhereHelper(nameof(RB_Building_Carrier_Extend.ID), carrmodel.ID), trans);
                                    if (flag)
                                    {
                                        var oldCarrierMetroList = carrierEnterpriseMetroApplyForRepository.GetCarrierMetroList(new RB_CarrierEnterpriseMetroApplyFor_Extend { MallBaseId = CarrierModel.MallBaseId, CarrierId = carrmodel.ID });
                                        carrierEnterpriseMetroApplyForRepository.DeleteBatch(oldCarrierMetroList);
                                        var mlist = MetroList.RefMapperToList<RB_CarrierEnterpriseMetroApplyFor_Extend>();
                                        mlist.ForEach(x =>
                                        {
                                            x.ID = 0;
                                            x.CarrierId = carrmodel.ID;
                                            x.Status = 0;
                                            x.TenantId = CarrierModel.TenantId;
                                            x.MallBaseId = CarrierModel.MallBaseId;
                                        });
                                        carrierEnterpriseMetroApplyForRepository.InsertBatch(mlist);
                                    }
                                    #endregion
                                }
                                else
                                {
                                    #region 新增载体
                                    buildingCarrierModel.ID = 0;
                                    buildingCarrierModel.UserId = cmodel.CreateBy;
                                    if (!string.IsNullOrWhiteSpace(CarrierModel.StartingInfo))
                                    {
                                        buildingCarrierModel.FirstStoreTest = 1;
                                    }
                                    int Id = building_CarrierRepository.Insert(buildingCarrierModel, trans);
                                    if (Id > 0)
                                    {
                                        var mlist = MetroList.RefMapperToList<RB_CarrierEnterpriseMetroApplyFor_Extend>();
                                        mlist.ForEach(x =>
                                        {
                                            x.ID = 0;
                                            x.CarrierId = Id;
                                            x.Status = 0;
                                            x.TenantId = CarrierModel.TenantId;
                                            x.MallBaseId = CarrierModel.MallBaseId;
                                        });
                                        carrierEnterpriseMetroApplyForRepository.InsertBatch(mlist, trans);
                                    }
                                    #endregion
                                }
                            }
                        }
                        //企业服务
                        else if (cmodel.FirstShopType == 3)
                        {
                            var enterpriseServicesList = enterpriseServicesApplyRepository.GetEnterpriseServicesApplyRepository(new RB_EnterpriseServicesApply_Extend { MallBaseId = cmodel.MallBaseId, CompanyId = cmodel.CompanyId });
                            if (enterpriseServicesList != null && enterpriseServicesList.Any())
                            {
                                var enterpriseModel = enterpriseServicesList.FirstOrDefault();
                                if (enterpriseModel.ExistServiceId > 0)
                                {
                                    Dictionary<string, object> filedsBrand = new Dictionary<string, object>()
                                    {
                                        { nameof(RB_EnterpriseServices_Extend.Name),enterpriseModel.Name},
                                        { nameof(RB_EnterpriseServices_Extend.Banner),enterpriseModel.Banner},
                                        { nameof(RB_EnterpriseServices_Extend.Introduction),enterpriseModel.Introduction},
                                        { nameof(RB_EnterpriseServices_Extend.DevIntention),enterpriseModel.DevIntention},
                                        { nameof(RB_EnterpriseServices_Extend.CategoryId),enterpriseModel.CategoryId},
                                        { nameof(RB_EnterpriseServices_Extend.Address),enterpriseModel.Address},
                                        { nameof(RB_EnterpriseServices_Extend.LatAndLon),enterpriseModel.LatAndLon},
                                        { nameof(RB_EnterpriseServices_Extend.OperationTime),enterpriseModel.OperationTime},
                                        { nameof(RB_EnterpriseServices_Extend.EType),enterpriseModel.EType},
                                        { nameof(RB_EnterpriseServices_Extend.Renovation),enterpriseModel.Renovation},
                                        { nameof(RB_EnterpriseServices_Extend.Payment),enterpriseModel.Payment},
                                        { nameof(RB_EnterpriseServices_Extend.HandoverDate),enterpriseModel.HandoverDate},
                                        { nameof(RB_EnterpriseServices_Extend.IntentionalFloor),enterpriseModel.IntentionalFloor},
                                        { nameof(RB_EnterpriseServices_Extend.ElevatorNum),enterpriseModel.ElevatorNum},
                                        { nameof(RB_EnterpriseServices_Extend.PropertyFee),enterpriseModel.PropertyFee},
                                        { nameof(RB_EnterpriseServices_Extend.RentFee),enterpriseModel.RentFee},
                                        { nameof(RB_EnterpriseServices_Extend.ContactName),enterpriseModel.ContactName},
                                        { nameof(RB_EnterpriseServices_Extend.ContactPhone),enterpriseModel.ContactPhone},
                                        { nameof(RB_EnterpriseServices_Extend.UpdateBy),enterpriseModel.UpdateBy},
                                        { nameof(RB_EnterpriseServices_Extend.UpdateDate),enterpriseModel.UpdateDate},
                                    };
                                    enterpriseServicesRepository.Update(filedsBrand, new WhereHelper(nameof(RB_EnterpriseServices_Extend.ServiceId), enterpriseModel.ExistServiceId), trans);
                                }
                                else
                                {
                                    var inserBModel = enterpriseModel.RefMapperTo<RB_EnterpriseServices_Extend>();
                                    inserBModel.ServiceId = 0;
                                    inserBModel.UserId = cmodel.CreateBy;
                                    enterpriseServicesRepository.Insert(inserBModel, trans);
                                }
                            }
                        }
                        //楼宇
                        else if (cmodel.FirstShopType == 4)
                        {
                            var buildingList = buildingApplyForRepository.GetBuildingRepository(new RB_BuildingApplyFor_Extend { MallBaseId = cmodel.MallBaseId, CompanyId = cmodel.CompanyId });
                            if (buildingList != null && buildingList.Any())
                            {
                                var buildingModel = buildingList.FirstOrDefault();
                                if (buildingModel.ExistBuildId > 0)
                                {
                                    Dictionary<string, object> filedsBrand = new Dictionary<string, object>()
                                    {
                                        { nameof(RB_Building_Extend.Name),buildingModel.Name},
                                        { nameof(RB_Building_Extend.Banner),buildingModel.Banner},
                                        { nameof(RB_Building_Extend.Address),buildingModel.Address},
                                        { nameof(RB_Building_Extend.LatAndLon),buildingModel.LatAndLon},
                                        { nameof(RB_Building_Extend.OperationTime),buildingModel.OperationTime},
                                        { nameof(RB_Building_Extend.CategoryId),buildingModel.CategoryId},
                                        { nameof(RB_Building_Extend.Areas),buildingModel.Areas},
                                        { nameof(RB_Building_Extend.BuildingNum),buildingModel.BuildingNum},
                                        { nameof(RB_Building_Extend.FloorNum),buildingModel.FloorNum},
                                        { nameof(RB_Building_Extend.ElevatorNum),buildingModel.ElevatorNum},
                                        { nameof(RB_Building_Extend.FloorHeight),buildingModel.FloorHeight},
                                        { nameof(RB_Building_Extend.Developers),buildingModel.Developers},
                                        { nameof(RB_Building_Extend.PropertyComp),buildingModel.PropertyComp},
                                        { nameof(RB_Building_Extend.SaleOrSelf),buildingModel.SaleOrSelf},
                                        { nameof(RB_Building_Extend.IsAllOperate),buildingModel.IsAllOperate},
                                        { nameof(RB_Building_Extend.ConstructionTime),buildingModel.ConstructionTime},
                                        { nameof(RB_Building_Extend.PropertyFee),buildingModel.PropertyFee},
                                        { nameof(RB_Building_Extend.RentFee),buildingModel.RentFee},
                                        { nameof(RB_Building_Extend.IndustryDirection),buildingModel.IndustryDirection},
                                        { nameof(RB_Building_Extend.BrandDemand),buildingModel.BrandDemand},
                                        { nameof(RB_Building_Extend.Other),buildingModel.Other},
                                        { nameof(RB_Building_Extend.ContactName),buildingModel.ContactName},
                                        { nameof(RB_Building_Extend.ContactPhone),buildingModel.ContactPhone},
                                        { nameof(RB_Building_Extend.UpdateBy),buildingModel.UpdateBy},
                                        { nameof(RB_Building_Extend.UpdateDate),buildingModel.UpdateDate},
                                    };
                                    buildingRepository.Update(filedsBrand, new WhereHelper(nameof(RB_Building_Extend.BuildId), buildingModel.ExistBuildId), trans);
                                }
                                else
                                {
                                    var inserBModel = buildingModel.RefMapperTo<RB_Building_Extend>();
                                    inserBModel.BuildId = 0;
                                    inserBModel.UserId = cmodel.CreateBy;
                                    buildingRepository.Insert(inserBModel, trans);
                                }
                            }
                        }
                    }
                }
                companyEnterpriseRepository.DBSession.Commit();
                return flag ? "" : "出错了，请联系管理员";
            }
            catch (Exception ex)
            {
                LogHelper.Write(ex, "UpdateCompanyStatus");
                companyEnterpriseRepository.DBSession.Rollback();
                return "出错了，请联系管理员";
            }
        }
        #endregion


        #region 访问量统计
        /// <summary>
        /// 获取访问记录信息
        /// </summary>
        /// <param name="query"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <returns></returns>
        public List<RB_Visit_Log_Extend> GetTopStatisticsList(RB_Visit_Log_Extend query)
        {
            var list = visit_LogRepository.GetTopStatisticsList(query);
            if (list != null && list.Any())
            {
                string productIds = string.Join(",", list.Select(x => x.ProductID).Distinct());

                if (query.ProductType == 1)
                {
                    var productList = building_CarrierRepository.GetBuildingCarrierListRepository(new RB_Building_Carrier_Extend { TenantId = query.TenantId, MallBaseId = query.MallBaseId, SelectIds = productIds, OpeningStatus = -1 });
                    list.ForEach(x => x.ProductName = productList?.FirstOrDefault(z => z.ID == x.ProductID)?.CarrierName ?? "");
                }
                else if (query.ProductType == 2) { }
                else if (query.ProductType == 3)
                {
                    var productList = brand_EnterpriseRepository.GetBrandEnterpriseListRepository(new RB_Brand_Enterprise_Extend { TenantId = query.TenantId, MallBaseId = query.MallBaseId, SelectIds = productIds });
                    list.ForEach(x => x.ProductName = productList?.FirstOrDefault(z => z.ID == x.ProductID)?.BrandName ?? "");
                }

                else if (query.ProductType == 4) { }

            }
            return list;
        }
        #endregion


        #region 收藏
        /// <summary>
        /// 分页列表
        /// </summary>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">每页显示条数</param>
        /// <param name="rowCount">总条数</param>
        /// <param name="query">查询条件</param>
        /// <returns></returns>
        public List<RB_Collect_Extend> GetMyCollectEnterprisePage(int pageIndex, int pageSize, out long rowCount, RB_Collect_Extend query)
        {
            var list = collectRepository.GetPageList(pageIndex, pageSize, out rowCount, query);
            string sourceIds = "";
            if (list != null && list.Any())
            {
                sourceIds = string.Join(",", list.Select(x => x.SourceId));
            }
            if (query.Type == 1)//1-载体
            {
                if (!string.IsNullOrEmpty(sourceIds))
                {
                    var sourceList = GetBuildingCarrierListModule(new RB_Building_Carrier_Extend { TenantId = query.TenantId, MallBaseId = query.MallBaseId, SelectIds = sourceIds });
                    foreach (var item in list)
                    {
                        RB_Building_Carrier_Extend carrierModel = sourceList.Where(x => x.ID == item.SourceId).FirstOrDefault();
                        if (carrierModel != null && carrierModel.ID > 0)
                        {
                            item.SourceName = carrierModel.CarrierName;
                            item.Address = carrierModel.Address;
                            item.ProjectName = carrierModel.CategoryName;
                            item.ProjectId = carrierModel.CategoryId;
                            item.BannerList = carrierModel.BannerList;
                        }
                    }
                }
            }
            else if (query.Type == 2)//2-品牌
            {
                if (!string.IsNullOrEmpty(sourceIds))
                {
                    var sourceList = GetBrandEnterpriseListModule(new RB_Brand_Enterprise_Extend
                    {
                        TenantId = query.TenantId,
                        MallBaseId = query.MallBaseId,
                        SelectIds = sourceIds,
                        RanQi = -1,
                        KongTiao = -1,
                        XinFeng = -1,
                        Plumbing = -1,
                        Caliber = -1,
                        Sewage = -1,
                        PaiYan = -1,
                    });
                    foreach (var item in list)
                    {
                        RB_Brand_Enterprise_Extend carrierModel = sourceList.Where(x => x.ID == item.SourceId).FirstOrDefault();
                        if (carrierModel != null && carrierModel.ID > 0)
                        {
                            if (!string.IsNullOrWhiteSpace(carrierModel.Banner))
                            {
                                carrierModel.BannerList = JsonConvert.DeserializeObject<List<string>>(carrierModel.Banner);
                            }
                            item.SourceName = carrierModel.BrandName;
                            item.SourceFullName = carrierModel.FullBrandName;
                            item.ProjectName = carrierModel.CategoryName;
                            item.ProjectId = carrierModel.CategoryId;
                            item.BannerList = carrierModel.BannerList;
                        }
                    }
                }
            }
            else if (query.Type == 3)//企业
            {
                if (!string.IsNullOrEmpty(sourceIds))
                {
                    var sourceList = enterpriseServicesRepository.GetEnterpriseServicesListRepository(new RB_EnterpriseServices_Extend
                    {
                        TenantId = query.TenantId,
                        MallBaseId = query.MallBaseId,
                        SelectIds = sourceIds,
                    });
                    foreach (var item in list)
                    {
                        RB_EnterpriseServices_Extend carrierModel = sourceList.Where(x => x.ServiceId == item.SourceId).FirstOrDefault();
                        if (carrierModel != null && carrierModel.ServiceId > 0)
                        {
                            if (!string.IsNullOrWhiteSpace(carrierModel.Banner))
                            {
                                carrierModel.BannerList = JsonConvert.DeserializeObject<List<string>>(carrierModel.Banner);
                            }
                            item.SourceName = carrierModel.Name;
                            item.SourceFullName = carrierModel.Name;
                            item.ProjectName = carrierModel.CategoryName;
                            item.ProjectId = carrierModel.CategoryId;
                            item.BannerList = carrierModel.BannerList;
                        }
                    }
                }
            }
            else if (query.Type == 4)//楼宇
            {
                if (!string.IsNullOrEmpty(sourceIds))
                {
                    var sourceList = buildingRepository.GetBuildingRepository(new RB_Building_Extend
                    {
                        TenantId = query.TenantId,
                        MallBaseId = query.MallBaseId,
                        QIds = sourceIds,
                    });
                    foreach (var item in list)
                    {
                        RB_Building_Extend carrierModel = sourceList.Where(x => x.BuildId == item.SourceId).FirstOrDefault();
                        if (carrierModel != null && carrierModel.BuildId > 0)
                        {
                            if (!string.IsNullOrWhiteSpace(carrierModel.Banner))
                            {
                                carrierModel.BannerList = JsonConvert.DeserializeObject<List<string>>(carrierModel.Banner);
                            }
                            item.SourceName = carrierModel.Name;
                            item.SourceFullName = carrierModel.Name;
                            item.ProjectName = carrierModel.CategoryName;
                            item.ProjectId = carrierModel.CategoryId;
                            item.BannerList = carrierModel.BannerList;
                        }
                    }
                }
            }
            return list;
        }
        #endregion
    }
}
