Пример #1
0
        /// <summary>
        /// 更新分店信息
        /// </summary>
        /// <param name="sonStore"></param>
        /// <returns></returns>
        public Tuple <bool, string> UpdateSonStore(SonStoreInfoParam sonStore)
        {
            var count = helper.QueryScalar($@"select Count(1) from [User] where Phone='{sonStore.Phone}' and Id not in ({sonStore.Id})");

            if (Convert.ToInt32(count) > 0)
            {
                return(Tuple.Create(false, "该手机号已经存在"));
            }

            var count1 = helper.QueryScalar($@"select Count(1) from [StoreDetailInfo] where StoreName='{sonStore.StoreName}' and UserId not in ({sonStore.Id})");

            if (Convert.ToInt32(count1) > 0)
            {
                return(Tuple.Create(false, "该分店名称已经存在"));
            }

            var temp = helper.QueryScalar($@"select [Password] from [User] where Id={sonStore.Id}");

            if (temp == null)
            {
                return(Tuple.Create(false, "异常参数"));
            }
            string password = temp.ToString();

            if (password != sonStore.Password)
            {
                password = Util.MD5Encrypt(sonStore.Password);
            }
            string sql = $@"update [User] set StaffName='{sonStore.StoreName}',Phone='{sonStore.Phone}',Password='******'
where Id={sonStore.Id};update StoreDetailInfo set StoreName='{sonStore.StoreName}' where UserId={sonStore.Id};";

            return(Tuple.Create(helper.Execute(sql) > 0 ? true : false, string.Empty));
        }
Пример #2
0
        /// <summary>
        /// 添加分店
        /// </summary>
        /// <param name="token"></param>
        /// <param name="sonStore"></param>
        /// <returns></returns>
        public Tuple <bool, string> AddSonStore(string token, SonStoreInfoParam sonStore)
        {
            var temp = helper.QueryScalar($@"select Count(1) from [User] where Phone='{sonStore.Phone}'");

            if (Convert.ToInt32(temp) > 0)
            {
                return(Tuple.Create(false, "该手机号已经存在,无法添加"));
            }
            var count1 = helper.QueryScalar($@"select Count(1) from [StoreDetailInfo] where StoreName='{sonStore.StoreName}' and UserId not in ({sonStore.Id})");

            if (Convert.ToInt32(count1) > 0)
            {
                return(Tuple.Create(false, "该分店名称已经存在"));
            }


            // 先根据token,Id,再获取,获取 StoreCode,然后再添加Staff
            UserEntity user = helper.Query <UserEntity>($@"select a.* from [User] a left join [UserAccessToken] b on a.Id=b.UserId where b.TokenId='{token}'").FirstOrDefault();

            if (user.UserType != 2)
            {
                return(Tuple.Create(false, "当前账号不是商家,无法创建分店"));
            }
            if (!user.StoreManage)
            {
                return(Tuple.Create(false, "当前账号没有管理分店的权限"));
            }
            if (string.IsNullOrWhiteSpace(user.StoreCode))
            {
                return(Tuple.Create(false, "该账号无法添加员工"));
            }

            var statistics = GetSonStoreStatistic(token);

            if (statistics.Item3 <= statistics.Item4)
            {
                return(Tuple.Create(false, "该商家最多允许拥有" + statistics.Item3 + "个分店,已经拥有" + statistics.Item4 + "个,无法继续添加"));
            }
            var storeId = helper.QueryScalar($@"select Id from [User] where StoreCode='{user.StoreCode}' and UserType=2 and IsMain=1;");

            var p = new DynamicParameters();

            p.Add("@Id", dbType: DbType.Int32, direction: ParameterDirection.Output);
            var    result = helper.Execute($@"insert into [User] (StoreCode,StaffName,Phone,Password,Enable,Status,UserType)
values ('{user.StoreCode}','{sonStore.StoreName}','{sonStore.Phone}','{Util.MD5Encrypt(sonStore.Password)}',
'{true}','{true}',{3}); SELECT @Id=SCOPE_IDENTITY()", p);
            var    id     = p.Get <int>("@Id");
            string sql    = $@"insert into StoreDetailInfo (UserId,StoreName,Enabled,CreateTime) 
values ({id},'{sonStore.StoreName}',{1},'{DateTime.Now}')";

            if (storeId != null)
            {
                helper.Execute($@"update StoreDetailInfo set ValidSonStoreNum = ValidSonStoreNum+1 where UserId={storeId}");
            }
            return(Tuple.Create(helper.Execute(sql) > 0 ? true : false, string.Empty));
        }
Пример #3
0
        public ResponseResultDto <bool> UpdateSonStore(SonStoreInfoParam sonStore)
        {
            if (!Util.ValidateMobilePhone(sonStore.Phone))
            {
                return(new ResponseResultDto <bool>
                {
                    IsSuccess = false,
                    ErrorMessage = "手机号格式不正确",
                    Result = false
                });
            }
            var result = storeApiRepository.UpdateSonStore(sonStore);

            return(new ResponseResultDto <bool>
            {
                IsSuccess = result.Item1,
                ErrorMessage = result.Item2,
                Result = result.Item1
            });
        }
Пример #4
0
        public ResponseResultDto <bool> AddSonStore(SonStoreInfoParam sonStore)
        {
            if (!Util.ValidateMobilePhone(sonStore.Phone))
            {
                return(new ResponseResultDto <bool>
                {
                    IsSuccess = false,
                    ErrorMessage = "手机号格式不正确",
                    Result = false
                });
            }
            HttpRequest request = HttpContext.Current.Request;
            string      token   = request.Headers.GetValues("Access-Token").FirstOrDefault();
            var         result  = storeApiRepository.AddSonStore(token, sonStore);

            return(new ResponseResultDto <bool>
            {
                IsSuccess = result.Item1,
                ErrorMessage = result.Item2,
                Result = result.Item1
            });
        }