Esempio n. 1
0
        public List <PlatChildGoods> GetSyncGoods(int aid, out int totalCount, string storeName = "", string goodsName = "", int goodsSync = -1, string categoryName = "", int pageSize = 10, int pageIndex = 1, int isFirstType = 0, int categoryId = 0, string appId = "")
        {
            List <PlatChildGoods> list = new List <PlatChildGoods>();
            int        count           = 0;
            List <int> listStoreAid    = new List <int>();
            //从中间表里获取该平台的店铺包括本平台入驻的跟代理商同步过来的
            List <PlatStoreRelation> listPlatStoreRelation = GetListStore(aid, out count, storeName, "", "", categoryName, 1, -1, -1, 1000, 1, "AddTime desc", string.Empty, isFirstType, categoryId, appId);

            foreach (PlatStoreRelation item in listPlatStoreRelation)
            {
                if (!listStoreAid.Contains(item.StoreAid))
                {
                    listStoreAid.Add(item.StoreAid);
                }
            }

            totalCount = 0;
            if (listStoreAid.Count > 0)
            {
                //从中间表里获取该平台的产品包括本平台入驻店铺的产品以及跟代理商同步过来的
                string goodsIds = PlatGoodsRelationBLL.SingleModel.GetGoodsIdsByAids(aid, goodsSync);

                if (!string.IsNullOrEmpty(goodsIds))
                {
                    List <MySqlParameter> parameters = new List <MySqlParameter>();
                    string strWhere = $" Id in({goodsIds}) and Tag=1 and State=1 and Aid in({string.Join(",", listStoreAid)}) ";


                    if (!string.IsNullOrEmpty(goodsName))
                    {
                        parameters.Add(new MySqlParameter("@goodsName", $"%{goodsName}%"));
                        strWhere += " and Name like @goodsName";
                    }
                    list = PlatChildGoodsBLL.SingleModel.GetListByParam(strWhere, parameters.ToArray(), pageSize, pageIndex, "Id,AId,Name,Price,VirtualSalesCount,SalesCount,Stock,Img,Unit", " sort desc, id desc ");
                    if (list != null)
                    {
                        list.ForEach(x =>
                        {
                            PlatGoodsRelation goodsRelation = PlatGoodsRelationBLL.SingleModel.GetPlatGoodsRelation(aid, x.Id);
                            if (goodsRelation != null)
                            {
                                x.Synchronized = goodsRelation.Synchronized;
                            }

                            PlatStoreRelation platStoreRelation = listPlatStoreRelation.FirstOrDefault(y => y.StoreAid == x.AId);
                            if (platStoreRelation != null)
                            {
                                x.StoreName             = platStoreRelation.StoreName;
                                x.CurFirstCategoryName  = platStoreRelation.CurFirstCategoryName;
                                x.CurSecondCategoryName = platStoreRelation.CurSecondCategoryName;
                            }
                        });

                        totalCount = PlatChildGoodsBLL.SingleModel.GetCount(strWhere, parameters.ToArray());
                    }
                }
            }

            return(list);
        }
Esempio n. 2
0
        public ActionResult TBPlatStoreTime()
        {
            TransactionModel transaction = new TransactionModel();
            List <PlatStore> list        = PlatStoreBLL.SingleModel.GetList("addtime='0001-01-01 00:00:00'", 1000, 1, "Id");
            int i = 0;

            foreach (PlatStore item in list)
            {
                PlatStoreRelation platStoreRelation = PlatStoreRelationBLL.SingleModel.GetModel($"StoreId={item.Id}");
                if (platStoreRelation != null)
                {
                    item.AddTime    = platStoreRelation.AddTime;
                    item.UpdateTime = platStoreRelation.UpdateTime;
                    transaction.Add(PlatStoreBLL.SingleModel.BuildUpdateSql(item, "AddTime,UpdateTime"));
                    i++;
                }
            }
            if (transaction.sqlArray != null && transaction.sqlArray.Length > 0)
            {
                if (PlatStoreBLL.SingleModel.ExecuteTransactionDataCorect(transaction.sqlArray))
                {
                    return(Content($"ok={i}"));
                }

                return(Content($"error={i}"));
            }
            else
            {
                return(Content($"ok:没有数据"));
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 查看店铺详情
        /// </summary>
        /// <returns></returns>
        public ActionResult StoreDetail()
        {
            int appId           = Utility.IO.Context.GetRequestInt("aid", 0);
            int storeRelationId = Utility.IO.Context.GetRequestInt("storeRelationId", 0);

            if (appId <= 0)
            {
                return(View("PageError", new PlatReturnMsg()
                {
                    Msg = "参数错误!", code = "500"
                }));
            }

            PlatStoreRelation platStoreRelation = PlatStoreRelationBLL.SingleModel.GetModel(storeRelationId);

            if (platStoreRelation == null)
            {
                return(View("PageError", new PlatReturnMsg()
                {
                    Msg = "数据异常!", code = "404"
                }));
            }

            PlatStore platStore = PlatStoreBLL.SingleModel.GetModel(platStoreRelation.StoreId);

            if (platStore == null)
            {
                return(View("PageError", new PlatReturnMsg()
                {
                    Msg = "店铺不存在!", code = "404"
                }));
            }


            return(View(platStore));
        }
Esempio n. 4
0
        /// <summary>
        /// 更改店铺在平台的显示类别
        /// </summary>
        /// <returns></returns>
        public ActionResult UpdateStoreRelationCategory()
        {
            result = new PlatReturnMsg();
            int appId           = Utility.IO.Context.GetRequestInt("appId", 0);
            int storeRelationId = Utility.IO.Context.GetRequestInt("storeRelationId", 0);
            int categoryId      = Utility.IO.Context.GetRequestInt("Id", 0);

            if (appId <= 0 || storeRelationId <= 0 || categoryId <= 0)
            {
                result.Msg = "参数错误";
                return(Json(result, JsonRequestBehavior.AllowGet));
            }

            PlatStoreRelation platStoreRelation = PlatStoreRelationBLL.SingleModel.GetModel(storeRelationId);

            if (platStoreRelation == null || platStoreRelation.Aid != appId)
            {
                result.Msg = "操作异常";
                return(Json(result, JsonRequestBehavior.AllowGet));
            }

            TransactionModel tranModel = new TransactionModel();

            platStoreRelation.Category   = categoryId;
            platStoreRelation.UpdateTime = DateTime.Now;
            tranModel.Add(PlatStoreRelationBLL.SingleModel.BuildUpdateSql(platStoreRelation, "Category,UpdateTime"));
            if (platStoreRelation.FromType == 0)
            {
                //表示店铺入驻过来的,也就是本平台的 还需要更改店铺类别
                //否则没有权限更改店铺里的类别 只能更改在本平台显示的店铺类别 因为是同步其它代理商的
                PlatStore platStore = PlatStoreBLL.SingleModel.GetModel(platStoreRelation.StoreId);
                if (platStore == null && platStore.BindPlatAid != appId)
                {
                    result.Msg = "暂无权限操作";
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }
                platStore.Category   = categoryId;
                platStore.UpdateTime = DateTime.Now;
                tranModel.Add(PlatStoreBLL.SingleModel.BuildUpdateSql(platStore, "Category,UpdateTime"));
            }

            if (tranModel.sqlArray != null && tranModel.sqlArray.Length > 0)
            {
                if (PlatStoreRelationBLL.SingleModel.ExecuteTransactionDataCorect(tranModel.sqlArray))
                {
                    result.isok = true;
                    result.Msg  = "操作成功";
                    return(Json(result));
                }
                else
                {
                    result.Msg = "操作失败";
                    return(Json(result));
                }
            }
            else
            {
                result.Msg = "没有需要更新的数据";
                return(Json(result));
            }
        }
Esempio n. 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="aid">平台小程序appId</param>
        /// <param name="totalCount"></param>
        /// <param name="storeName">店铺名称</param>
        /// <param name="appName">绑定的小程序名称</param>
        /// <param name="agentName">分销代理商名称</param>
        /// <param name="categoryName">原平台类别名称</param>
        /// <param name="storeState">店铺状态</param>
        /// <param name="haveAid">是否绑定了小程序0 未绑定 1绑定了</param>
        /// <param name="fromType">数据来源0 店铺入驻 1代理分销商同步</param>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <param name="orderWhere"></param>
        /// <returns></returns>
        public List <PlatStoreRelation> GetListStore(int aid, out int totalCount, string storeName = "", string appName = "", string agentName = "", string categoryName = "", int storeState = -1, int haveAid = -1, int fromType = -1, int pageSize = 10, int pageIndex = 1, string orderWhere = "AddTime desc", string storeOwnerPhone = "", int isFirstType = 0, int categoryId = 0, string appId = "")
        {
            List <PlatStore>         list = new List <PlatStore>();
            List <PlatStoreRelation> listPlatStoreRelation = new List <PlatStoreRelation>();
            List <MySqlParameter>    parameters            = new List <MySqlParameter>();
            string strWhere = $" psr.Aid={aid} and s.Id>0 and s.state<>-1 and s.MyCardId in({PlatMyCardBLL.SingleModel.GetCardIds(aid, appId)})";

            if (storeState != -1)
            {
                strWhere += $" and psr.State={storeState}";
            }
            if (haveAid != -1)
            {
                if (haveAid == 0)
                {
                    strWhere += $" and s.Aid=0";
                }
                else
                {
                    strWhere += $" and s.Aid<>0"; //表示店铺已经绑定独立小程序
                }
            }

            if (fromType != -1)
            {
                strWhere += $" and psr.FromType={fromType}";
            }

            if (!string.IsNullOrEmpty(storeOwnerPhone))
            {
                parameters.Add(new MySqlParameter("@storeOwnerPhone", $"%{storeOwnerPhone}%"));
                strWhere += " and c.Phone like @storeOwnerPhone";
            }

            if (!string.IsNullOrEmpty(storeName))
            {
                parameters.Add(new MySqlParameter("@storeName", $"%{storeName}%"));
                strWhere += " and s.Name like @storeName";
            }
            if (!string.IsNullOrEmpty(appName))//根据店铺绑定的小程序名称模糊查询
            {
                List <int> listRids = OpenAuthorizerConfigBLL.SingleModel.GetRidByAppName(appName);
                if (listRids == null || listRids.Count <= 0)
                {
                    listRids.Add(0);
                }
                strWhere += $" and s.Aid in ({string.Join(",", listRids)})";
            }
            if (!string.IsNullOrEmpty(agentName))//根据分销代理商名称模糊查询
            {
                List <int> listAgentId = AgentinfoBLL.SingleModel.GetAgentIdByAgentName(agentName);
                if (listAgentId == null || listAgentId.Count <= 0)
                {
                    listAgentId.Add(0);
                }
                strWhere += $" and psr.AgentId in ({string.Join(",", listAgentId)})";
            }

            if (!string.IsNullOrEmpty(categoryName))//根据类别名称(小类 因为店铺最终属于某个小类)模糊查询
            {
                List <int> listCategoryId = PlatStoreCategoryBLL.SingleModel.GetCategoryIdName(categoryName);
                if (listCategoryId == null || listCategoryId.Count <= 0)
                {
                    listCategoryId.Add(0);
                }

                strWhere += $" and s.Category in ({string.Join(",", listCategoryId)})";
            }

            if (isFirstType == 1 && categoryId > 0)
            {
                //表示传过来的是店铺大类 先查询出其下面的小类id
                strWhere += $" and s.Category in ({PlatStoreCategoryBLL.SingleModel.GetChildIds(aid, categoryId)})";
            }

            if (isFirstType == 2 && categoryId > 0)
            {
                //表示传过来的是店铺大类 先查询出其下面的小类id
                strWhere += $" and s.Category in ({categoryId})";
            }

            string sql = $"select psr.*,s.YearCount,s.CostPrice,s.Id as sId,s.Aid as sAid,s.Category as sCategory,s.MyCardId as sMyCardId,s.StorePV,s.StoreVirtualPV,s.Name,c.Phone as StoreOwnerPhone from PlatStoreRelation psr left join PlatStore s on psr.StoreId=s.Id left join PlatMyCard c on s.MyCardId=c.Id  where {strWhere} order by {orderWhere} LIMIT {(pageIndex - 1) * pageSize},{pageSize}";

            using (var dr = SqlMySql.ExecuteDataReader(Utility.dbEnum.MINIAPP.ToString(), CommandType.Text, sql, parameters.ToArray()))
            {
                listPlatStoreRelation = new List <PlatStoreRelation>();
                while (dr.Read())
                {
                    PlatStoreRelation platStoreRelation = PlatStoreRelationBLL.SingleModel.GetModel(dr);

                    if (platStoreRelation != null)
                    {
                        if (dr["sCategory"] != DBNull.Value)
                        {
                            PlatStoreCategory OwnerPlatStoreCategory = PlatStoreCategoryBLL.SingleModel.GetModel(Convert.ToInt32(dr["sCategory"]));
                            if (OwnerPlatStoreCategory != null)
                            {
                                platStoreRelation.OwnerSecondCategoryName = OwnerPlatStoreCategory.Name;
                                PlatStoreCategory firstplatStoreCategory = PlatStoreCategoryBLL.SingleModel.GetModel(OwnerPlatStoreCategory.ParentId);
                                if (firstplatStoreCategory != null)
                                {
                                    platStoreRelation.OwnerFirstCategoryName = firstplatStoreCategory.Name;
                                }
                            }
                        }

                        PlatStoreCategory CurPlatStoreCategory = PlatStoreCategoryBLL.SingleModel.GetModel(platStoreRelation.Category);
                        if (CurPlatStoreCategory != null)
                        {
                            platStoreRelation.CurSecondCategoryName = CurPlatStoreCategory.Name;
                            PlatStoreCategory firstplatStoreCategory = PlatStoreCategoryBLL.SingleModel.GetModel(CurPlatStoreCategory.ParentId);
                            if (firstplatStoreCategory != null)
                            {
                                platStoreRelation.CurFirstCategoryName = firstplatStoreCategory.Name;
                                platStoreRelation.FirstCategory        = CurPlatStoreCategory.ParentId;
                            }
                        }


                        platStoreRelation.StoreOwnerPhone = dr["StoreOwnerPhone"].ToString();
                        if (dr["sMyCardId"] != DBNull.Value)
                        {
                            platStoreRelation.MyCardId = Convert.ToInt32(dr["sMyCardId"]);
                        }

                        Agentinfo agentinfo = AgentinfoBLL.SingleModel.GetModel(platStoreRelation.AgentId);
                        platStoreRelation.FromTypeStr = platStoreRelation.FromType == 0 ? "平台入驻" : (agentinfo != null ? agentinfo.name : "分销代理商");

                        if (dr["sAid"] != DBNull.Value)
                        {
                            XcxAppAccountRelation xcxAppAccountRelation = XcxAppAccountRelationBLL.SingleModel.GetModel(Convert.ToInt32(dr["sAid"]));
                            if (xcxAppAccountRelation == null)
                            {
                                platStoreRelation.BindAppIdName = "无";
                            }
                            else
                            {
                                OpenAuthorizerConfig openAuthorizerConfig = OpenAuthorizerConfigBLL.SingleModel.GetModelByAppids(xcxAppAccountRelation.AppId, xcxAppAccountRelation.Id);

                                platStoreRelation.BindAppIdName = openAuthorizerConfig?.nick_name + "id:" + xcxAppAccountRelation.Id;
                            }
                        }

                        platStoreRelation.StoreName = Convert.ToString(dr["Name"]);
                        if (dr["StorePV"] != DBNull.Value)
                        {
                            platStoreRelation.StorePV = Convert.ToInt32(dr["StorePV"]);
                        }
                        if (dr["StoreVirtualPV"] != DBNull.Value)
                        {
                            platStoreRelation.StorePV += Convert.ToInt32(dr["StoreVirtualPV"]);
                        }

                        if (dr["sId"] != DBNull.Value)
                        {
                            platStoreRelation.StoreId = Convert.ToInt32(dr["sId"]);
                        }
                        if (dr["sAid"] != DBNull.Value)
                        {
                            platStoreRelation.StoreAid = Convert.ToInt32(dr["sAid"]);
                        }

                        platStoreRelation.YearCount = Convert.ToInt32(dr["YearCount"]);
                        platStoreRelation.CostPrice = Convert.ToInt32(dr["CostPrice"]);

                        listPlatStoreRelation.Add(platStoreRelation);
                    }
                }
            }


            totalCount = 0;
            object obj = SqlMySql.ExecuteScalar(Utility.dbEnum.MINIAPP.ToString(), CommandType.Text, $"select Count(psr.Id) from PlatStoreRelation psr left join PlatStore s on psr.StoreId=s.Id left join PlatMyCard c on s.MyCardId=c.Id  where {strWhere}", parameters.ToArray());

            if (obj != null)
            {
                totalCount = Convert.ToInt32(obj);
            }
            ;



            return(listPlatStoreRelation);
        }
Esempio n. 6
0
        public ActionResult AddStore()
        {
            returnObj      = new Return_Msg_APP();
            returnObj.code = "200";
            string appId       = Context.GetRequest("appId", string.Empty);
            int    userId      = Context.GetRequestInt("myCardId", 0);
            int    agentInfoId = Context.GetRequestInt("agentInfoId", 0);

            if (string.IsNullOrEmpty(appId) || userId <= 0)
            {
                returnObj.Msg = "参数错误";
                return(Json(returnObj));
            }

            XcxAppAccountRelation r = _xcxAppAccountRelationBLL.GetModelByAppid(appId);

            if (r == null)
            {
                returnObj.Msg = "小程序未授权";
                return(Json(returnObj, JsonRequestBehavior.AllowGet));
            }

            Agentinfo agentinfo = AgentinfoBLL.SingleModel.GetModelByAccoundId(r.AccountId.ToString());
            //if (agentinfo == null)//本平台代理信息
            //{
            //    returnObj.Msg = "入驻异常";
            //    return Json(returnObj, JsonRequestBehavior.AllowGet);
            //}

            string banners = Context.GetRequest("banners", string.Empty);

            if (string.IsNullOrEmpty(banners) || banners.Split(',').Length <= 0)
            {
                returnObj.Msg = "轮播图至少一张";
                return(Json(returnObj));
            }
            string storeName = Context.GetRequest("storeName", string.Empty);

            if (string.IsNullOrEmpty(storeName) || storeName.Length >= 20)
            {
                returnObj.Msg = "店铺名称不能为空并且不能超过20字符";
                return(Json(returnObj));
            }

            string lngStr = Context.GetRequest("lng", string.Empty);
            string latStr = Context.GetRequest("lat", string.Empty);
            double lng    = 0.00;
            double lat    = 0.00;

            if (!double.TryParse(lngStr, out lng) || !double.TryParse(latStr, out lat))
            {
                returnObj.Msg = "地址坐标错误";
                return(Json(returnObj));
            }

            string location = Context.GetRequest("location", string.Empty);

            if (string.IsNullOrEmpty(location))
            {
                returnObj.Msg = "地址不能为空";
                return(Json(returnObj));
            }

            string storeService = Context.GetRequest("storeService", string.Empty);
            //if (string.IsNullOrEmpty(storeService) || storeService.Split(',').Length <= 0)
            //{
            //    returnObj.Msg = "提供服务不能为空";
            //    return Json(returnObj);
            //}

            string openTime = Context.GetRequest("openTime", string.Empty);
            //if (string.IsNullOrEmpty(openTime))
            //{
            //    returnObj.Msg = "营业时间不能为空";
            //    return Json(returnObj);
            //}
            //TODO 需要验证手机+电话
            string phone = Context.GetRequest("phone", string.Empty);

            if (string.IsNullOrEmpty(phone))
            {
                returnObj.Msg = "请填写正确的号码";
                return(Json(returnObj));
            }

            string businessDescription = Context.GetRequest("businessDescription", string.Empty);

            if (string.IsNullOrEmpty(businessDescription))
            {
                returnObj.Msg = "业务简述不能为空";
                return(Json(returnObj));
            }

            string storeDescription = Context.GetRequest("storeDescription", string.Empty);
            string storeImgs        = Context.GetRequest("storeImgs", string.Empty);
            int    category         = Context.GetRequestInt("category", 0);//店铺类别

            if (PlatStoreCategoryBLL.SingleModel.GetModel(category) == null)
            {
                returnObj.Msg = "类别选择错误!";
                return(Json(returnObj));
            }

            PlatStore platStore = PlatStoreBLL.SingleModel.GetPlatStore(userId, 1);

            if (platStore == null)
            {
                platStore = new PlatStore();
            }

            AddressApi addressinfo = AddressHelper.GetAddressByApi(lngStr, latStr);

            if (addressinfo == null || addressinfo.result == null || addressinfo.result.address_component == null)
            {
                returnObj.Msg = "地址出错!";
                return(Json(returnObj));
            }

            if (!storeService.Contains("ServiceState"))
            {
                //表示旧版本的数据,设施服务给初始化新值
                List <StoreServiceModel> list = new List <StoreServiceModel>();
                list.Add(new StoreServiceModel()
                {
                    ServiceState = true, ServiceName = "WIFI"
                });
                list.Add(new StoreServiceModel()
                {
                    ServiceState = true, ServiceName = "停车位"
                });
                list.Add(new StoreServiceModel()
                {
                    ServiceState = true, ServiceName = "支付宝支付"
                });
                list.Add(new StoreServiceModel()
                {
                    ServiceState = true, ServiceName = "微信支付"
                });
                list.Add(new StoreServiceModel()
                {
                    ServiceState = true, ServiceName = "刷卡支付"
                });
                list.Add(new StoreServiceModel()
                {
                    ServiceState = true, ServiceName = "空调雅座"
                });
                list.Add(new StoreServiceModel()
                {
                    ServiceState = true, ServiceName = "付费停车"
                });
                list.Add(new StoreServiceModel()
                {
                    ServiceState = true, ServiceName = "接送服务"
                });
                storeService = Newtonsoft.Json.JsonConvert.SerializeObject(list);
            }


            string storeRemark = Context.GetRequest("storeRemark", string.Empty);

            platStore.StoreRemark = storeRemark;

            string provinceName = addressinfo.result.address_component.province;
            string cityName     = addressinfo.result.address_component.city;
            string countryName  = addressinfo.result.address_component.district;

            platStore.ProvinceCode        = C_AreaBLL.SingleModel.GetCodeByName(provinceName);
            platStore.CityCode            = C_AreaBLL.SingleModel.GetCodeByName(cityName);
            platStore.CountryCode         = C_AreaBLL.SingleModel.GetCodeByName(countryName);
            platStore.AddTime             = DateTime.Now;
            platStore.Banners             = banners;
            platStore.BindPlatAid         = r.Id;
            platStore.BusinessDescription = businessDescription;
            platStore.Category            = category;
            platStore.Lat              = lat;
            platStore.Lng              = lng;
            platStore.Location         = location;
            platStore.MyCardId         = userId;
            platStore.Name             = storeName;
            platStore.OpenTime         = openTime;
            platStore.Phone            = phone;
            platStore.StoreDescription = storeDescription;
            platStore.StoreImgs        = storeImgs;
            platStore.StoreService     = storeService;
            platStore.UpdateTime       = DateTime.Now;
            TransactionModel TranModel = new TransactionModel();

            if (platStore.Id > 0)
            {
                //表示更新

                TranModel.Add(PlatStoreBLL.SingleModel.BuildUpdateSql(platStore));
                PlatStoreRelation platStoreRelation = PlatStoreRelationBLL.SingleModel.GetPlatStoreRelationOwner(r.Id, platStore.Id);
                if (platStoreRelation == null)
                {
                    returnObj.Msg = "更新异常(店铺关系找不到数据)";
                    return(Json(returnObj));
                }
                platStoreRelation.Category   = platStore.Category;
                platStoreRelation.UpdateTime = DateTime.Now;
                TranModel.Add(PlatStoreRelationBLL.SingleModel.BuildUpdateSql(platStoreRelation, "Category,UpdateTime"));

                //2.查找上级代理
                #region  步代理商店铺 暂时先屏蔽
                //AgentDistributionRelation agentDistributionRelationFirst = new AgentDistributionRelationBLL().GetModel(agentinfo.id);
                //if (agentDistributionRelationFirst != null)
                //{
                //    Agentinfo agentinfoFirst = _agentinfoBll.GetModel(agentDistributionRelationFirst.ParentAgentId);
                //    if (agentinfoFirst != null)
                //    {
                //        XcxAppAccountRelation xcxAppAccountRelationFirst = _xcxappaccountrelationBll.GetModelByaccountidAndTid(agentinfoFirst.useraccountid, (int)TmpType.小未平台);
                //        if (xcxAppAccountRelationFirst != null)
                //        {
                //            PlatStoreRelation platStoreRelationFist = _platStoreRelationBLL.GetPlatStoreRelationOwner(xcxAppAccountRelationFirst.Id, platStore.Id, agentinfo.id);
                //            if (platStoreRelationFist != null)
                //            {
                //                platStoreRelationFist.Category = platStore.Category;
                //                platStoreRelationFist.UpdateTime = DateTime.Now;
                //                TranModel.Add(_platStoreRelationBLL.BuildUpdateSql(platStoreRelationFist, "Category,UpdateTime"));
                //            }


                //            //3.查找上级的上级代理
                //            AgentDistributionRelation agentDistributionRelationSecond = new AgentDistributionRelationBLL().GetModel(agentinfoFirst.id);
                //            if (agentDistributionRelationSecond != null)
                //            {
                //                Agentinfo agentinfoSecond = _agentinfoBll.GetModel(agentDistributionRelationSecond.ParentAgentId);
                //                if (agentinfoSecond != null)
                //                {
                //                    XcxAppAccountRelation xcxAppAccountRelationSecond = _xcxappaccountrelationBll.GetModelByaccountidAndTid(agentinfoSecond.useraccountid, (int)TmpType.小未平台);
                //                    if (xcxAppAccountRelationSecond != null)
                //                    {
                //                        PlatStoreRelation platStoreRelationSecond = _platStoreRelationBLL.GetPlatStoreRelationOwner(xcxAppAccountRelationSecond.Id, platStore.Id, agentinfo.id);

                //                        platStoreRelationSecond.Category = platStore.Category;
                //                        platStoreRelationSecond.UpdateTime = DateTime.Now;
                //                        TranModel.Add(_platStoreRelationBLL.BuildUpdateSql(platStoreRelationSecond, "Category,UpdateTime"));
                //                    }
                //                }
                //            }
                //        }
                //    }
                //}
                #endregion


                if (TranModel.sqlArray != null && TranModel.sqlArray.Length > 0 && PlatStoreRelationBLL.SingleModel.ExecuteTransactionDataCorect(TranModel.sqlArray))
                {
                    returnObj.isok = true;
                    returnObj.Msg  = "操作成功";
                    return(Json(returnObj));
                }
                else
                {
                    returnObj.Msg = "更新失败";
                    return(Json(returnObj));
                }
            }
            else
            {
                //平台入驻模式
                PlatStoreAddSetting platStoreAddSetting = PlatStoreAddSettingBLL.SingleModel.GetPlatStoreAddSetting(r.Id);
                int addWay             = platStoreAddSetting != null ? platStoreAddSetting.AddWay : 0;
                PlatStoreAddRules rule = new PlatStoreAddRules();
                if (addWay == 1)
                {
                    platStore.State = -1;
                    int ruleId = Context.GetRequestInt("ruleId", 0);
                    rule = PlatStoreAddRulesBLL.SingleModel.getRule(r.Id, ruleId);
                    if (rule == null)
                    {
                        returnObj.Msg = "入驻套餐不存在!";
                        return(Json(returnObj));
                    }

                    platStore.YearCount = rule.YearCount;
                    platStore.CostPrice = rule.CostPrice;
                }

                //表示入驻平台 需要将该入驻店铺同步到平台的1 2级代理商
                int storeId = Convert.ToInt32(PlatStoreBLL.SingleModel.Add(platStore));

                if (storeId > 0)
                {
                    #region 数据同步

                    //插入关系表  才算成功 店铺数据都是从关系表获取才算有效的
                    //1.先将入驻到平台的插入
                    PlatStoreRelation platStoreRelation = new PlatStoreRelation();
                    platStoreRelation.StoreId    = storeId;
                    platStoreRelation.State      = 1;
                    platStoreRelation.FromType   = 0;
                    platStoreRelation.Aid        = r.Id;
                    platStoreRelation.Category   = platStore.Category;
                    platStoreRelation.AgentId    = agentinfo != null ? agentinfo.id : agentInfoId;
                    platStoreRelation.AddTime    = DateTime.Now;
                    platStoreRelation.UpdateTime = DateTime.Now;
                    TranModel.Add(PlatStoreRelationBLL.SingleModel.BuildAddSql(platStoreRelation));
                    //2.查找上级代理
                    #region 暂时先屏蔽
                    //AgentDistributionRelation agentDistributionRelationFirst = new AgentDistributionRelationBLL().GetModel(agentinfo.id);
                    //if (agentDistributionRelationFirst != null)
                    //{
                    //    Agentinfo agentinfoFirst = _agentinfoBll.GetModel(agentDistributionRelationFirst.ParentAgentId);
                    //    if (agentinfoFirst != null)
                    //    {
                    //        XcxAppAccountRelation xcxAppAccountRelationFirst = _xcxappaccountrelationBll.GetModelByaccountidAndTid(agentinfoFirst.useraccountid, (int)TmpType.小未平台);
                    //        if (xcxAppAccountRelationFirst != null)
                    //        {
                    //            PlatStoreRelation platStoreRelationFist = new PlatStoreRelation();
                    //            platStoreRelationFist.StoreId = storeId;
                    //            platStoreRelationFist.State = 0;
                    //            platStoreRelationFist.FromType = 1;
                    //            platStoreRelationFist.Aid = xcxAppAccountRelationFirst.Id;
                    //            platStoreRelationFist.Category = platStore.Category;
                    //            platStoreRelationFist.AgentId = agentinfo.id;
                    //            platStoreRelationFist.AddTime = DateTime.Now;
                    //            platStoreRelationFist.UpdateTime = DateTime.Now;
                    //            TranModel.Add(_platStoreRelationBLL.BuildAddSql(platStoreRelationFist));

                    //            //3.查找上级的上级代理
                    //            AgentDistributionRelation agentDistributionRelationSecond = new AgentDistributionRelationBLL().GetModel(agentinfoFirst.id);
                    //            if (agentDistributionRelationSecond != null)
                    //            {
                    //                Agentinfo agentinfoSecond = _agentinfoBll.GetModel(agentDistributionRelationSecond.ParentAgentId);
                    //                if (agentinfoSecond != null)
                    //                {
                    //                    XcxAppAccountRelation xcxAppAccountRelationSecond = _xcxappaccountrelationBll.GetModelByaccountidAndTid(agentinfoSecond.useraccountid, (int)TmpType.小未平台);
                    //                    if (xcxAppAccountRelationSecond != null)
                    //                    {
                    //                        PlatStoreRelation platStoreRelationSecond = new PlatStoreRelation();
                    //                        platStoreRelationSecond.StoreId = storeId;
                    //                        platStoreRelationSecond.State = 0;
                    //                        platStoreRelationSecond.FromType = 1;
                    //                        platStoreRelationSecond.Aid = xcxAppAccountRelationSecond.Id;
                    //                        platStoreRelationSecond.Category = platStore.Category;
                    //                        platStoreRelationSecond.AgentId = agentinfo.id;
                    //                        platStoreRelationSecond.AddTime = DateTime.Now;
                    //                        platStoreRelationSecond.UpdateTime = DateTime.Now;
                    //                        TranModel.Add(_platStoreRelationBLL.BuildAddSql(platStoreRelationSecond));
                    //                    }

                    //                }
                    //            }


                    //        }
                    //    }
                    //}
                    #endregion



                    #endregion
                    int orderid = 0;
                    if (addWay == 1)
                    {
                        CityMorders order = new CityMorders()
                        {
                            FuserId        = storeId,
                            Fusername      = storeName,
                            TuserId        = 0,
                            OrderType      = (int)ArticleTypeEnum.PlatAddStorePay,
                            ActionType     = (int)miniAppBuyMode.微信支付,
                            Addtime        = DateTime.Now,
                            Percent        = 99,//不收取服务费
                            userip         = WebHelper.GetIP(),
                            payment_status = 0,
                            Status         = 0,
                            CitySubId      = 0,//无分销,默认为0
                            PayRate        = 1,
                            appid          = appId,
                            Articleid      = rule.Id,
                            CommentId      = platStore.YearCount,
                            MinisnsId      = r.Id,
                            payment_free   = platStore.CostPrice,
                            ShowNote       = $"平台版店铺入驻收费付款{platStore.CostPrice * 0.01}元"
                        };
                        string no = WxPayApi.GenerateOutTradeNo();
                        order.orderno  = no;
                        order.trade_no = no;

                        orderid = Convert.ToInt32(_cityMordersBLL.Add(order));
                    }



                    if (TranModel.sqlArray != null && TranModel.sqlArray.Length > 0)
                    {
                        if (PlatStoreRelationBLL.SingleModel.ExecuteTransactionDataCorect(TranModel.sqlArray))
                        {
                            if (orderid <= 0 && addWay == 1)
                            {
                                returnObj.Msg = "入驻失败(订单生成失败)";
                                return(Json(returnObj));
                            }

                            returnObj.dataObj = new { storeId = storeId, orderid = orderid };
                            returnObj.isok    = true;
                            returnObj.Msg     = "入驻成功";
                            return(Json(returnObj));
                        }
                        else
                        {
                            platStore.State      = -1;
                            platStore.UpdateTime = DateTime.Now;
                            PlatStoreBLL.SingleModel.Update(platStore, "State,UpdateTime");
                            returnObj.Msg = "入驻失败";
                            return(Json(returnObj));
                        }
                    }
                    else
                    {
                        returnObj.dataObj = storeId;
                        returnObj.isok    = true;
                        returnObj.Msg     = "入驻成功";
                        return(Json(returnObj));
                    }
                }
                else
                {
                    returnObj.Msg = "入驻失败(请联系客服)";
                    return(Json(returnObj));
                }
            }
        }