using System;
using System.Collections.Generic;
using System.Linq;
// using MySystem.Models;

namespace MySystem
{
    public class PublicFunction
    {

        #region 生成创客Id
        public static int MakeUsersId()
        {
            string LockKey = "MakeUsersId";
            RedisDbconn.Instance.GetLock(LockKey);            
            int UsersId = RedisDbconn.Instance.Get<int>("UsersId");
            if(UsersId == 0) UsersId = 1;
            RedisDbconn.Instance.AddInt("UsersId");
            RedisDbconn.Instance.ReleaseLock(LockKey);
            return UsersId;
        }
        #endregion

        #region 生成消费者Id
        public static int MakeConsumerId()
        {
            string LockKey = "MakeConsumerId";
            RedisDbconn.Instance.GetLock(LockKey);            
            int ConsumerId = RedisDbconn.Instance.Get<int>("ConsumerId");
            if(ConsumerId == 0) ConsumerId = 1;
            RedisDbconn.Instance.AddInt("ConsumerId");
            RedisDbconn.Instance.ReleaseLock(LockKey);
            return ConsumerId;
        }
        #endregion

        #region 生成消费者支付订单Id
        public static int MakeConsumerOrderId()
        {
            string LockKey = "MakeConsumerOrderId";
            RedisDbconn.Instance.GetLock(LockKey);            
            int ConsumerOrderId = RedisDbconn.Instance.Get<int>("ConsumerOrderId");
            if(ConsumerOrderId == 0) ConsumerOrderId = 1;
            RedisDbconn.Instance.AddInt("ConsumerOrderId");
            RedisDbconn.Instance.ReleaseLock(LockKey);
            return ConsumerOrderId;
        }
        #endregion

        #region 生成创客收货地址Id
        public static int MakeUserAddressId()
        {
            string LockKey = "MakeUserAddressId";
            RedisDbconn.Instance.GetLock(LockKey);
            int UserAddressId = RedisDbconn.Instance.Get<int>("UserAddressId");
            if(UserAddressId == 0) UserAddressId = 1;
            RedisDbconn.Instance.AddInt("UserAddressId");
            RedisDbconn.Instance.ReleaseLock(LockKey);
            return UserAddressId;
        }
        #endregion

        #region 生成订单Id
        public static int MakeOrdersId()
        {
            string LockKey = "MakeOrdersId";
            RedisDbconn.Instance.GetLock(LockKey);
            int OrdersId = RedisDbconn.Instance.Get<int>("OrdersId");
            if(OrdersId == 0) OrdersId = 1;
            RedisDbconn.Instance.AddInt("OrdersId");
            RedisDbconn.Instance.ReleaseLock(LockKey);
            return OrdersId;
        }
        #endregion

        #region 生成订单商品Id
        public static int MakeOrderProductId()
        {
            string LockKey = "MakeOrderProductId";
            RedisDbconn.Instance.GetLock(LockKey);
            int OrderProductId = RedisDbconn.Instance.Get<int>("OrderProductId");
            if(OrderProductId == 0) OrderProductId = 1;
            RedisDbconn.Instance.AddInt("OrderProductId");
            RedisDbconn.Instance.ReleaseLock(LockKey);
            return OrderProductId;
        }
        #endregion

        #region 生成提现申请记录Id
        public static int MakeUserCashRecordId()
        {
            string LockKey = "MakeUserCashRecordId";
            RedisDbconn.Instance.GetLock(LockKey);
            int UserCashRecordId = RedisDbconn.Instance.Get<int>("UserCashRecordId");
            if(UserCashRecordId == 0) UserCashRecordId = 1;
            RedisDbconn.Instance.AddInt("UserCashRecordId");
            RedisDbconn.Instance.ReleaseLock(LockKey);
            return UserCashRecordId;
        }
        #endregion

        #region 生成创客变动记录Id
        public static int MakeUserStoreChangeId()
        {
            string LockKey = "MakeUserStoreChangeId";
            RedisDbconn.Instance.GetLock(LockKey);
            int UserStoreChangeId = RedisDbconn.Instance.Get<int>("UserStoreChangeId");
            if(UserStoreChangeId == 0) UserStoreChangeId = 1;
            RedisDbconn.Instance.AddInt("UserStoreChangeId");
            RedisDbconn.Instance.ReleaseLock(LockKey);
            return UserStoreChangeId;
        }
        #endregion

        #region 生成仓库变动记录Id
        public static int MakeStoreStockChangeId()
        {
            string LockKey = "MakeStoreStockChangeId";
            RedisDbconn.Instance.GetLock(LockKey);
            int StoreStockChangeId = RedisDbconn.Instance.Get<int>("StoreStockChangeId");
            if(StoreStockChangeId == 0) StoreStockChangeId = 1;
            RedisDbconn.Instance.AddInt("StoreStockChangeId");
            RedisDbconn.Instance.ReleaseLock(LockKey);
            return StoreStockChangeId;
        }
        #endregion

        #region 生成机具申请订单Id
        public static int MakeMachineApplyId()
        {
            string LockKey = "MakeMachineApplyId";
            RedisDbconn.Instance.GetLock(LockKey);
            int MachineApplyId = RedisDbconn.Instance.Get<int>("MachineApplyId");
            if(MachineApplyId == 0) MachineApplyId = 1;
            RedisDbconn.Instance.AddInt("MachineApplyId");
            RedisDbconn.Instance.ReleaseLock(LockKey);
            return MachineApplyId;
        }
        #endregion

        #region 生成开团申请记录Id
        public static int MakeTeamApplyId()
        {
            string LockKey = "MakeTeamApplyId";
            RedisDbconn.Instance.GetLock(LockKey);
            int TeamApplyId = RedisDbconn.Instance.Get<int>("TeamApplyId");
            if(TeamApplyId == 0) TeamApplyId = 1;
            RedisDbconn.Instance.AddInt("TeamApplyId");
            RedisDbconn.Instance.ReleaseLock(LockKey);
            return TeamApplyId;
        }
        #endregion

        #region 生成参团申请记录Id
        public static int MakeTeamOfferApplyId()
        {
            string LockKey = "MakeTeamOfferApplyId";
            RedisDbconn.Instance.GetLock(LockKey);
            int TeamOfferApplyId = RedisDbconn.Instance.Get<int>("TeamOfferApplyId");
            if(TeamOfferApplyId == 0) TeamOfferApplyId = 1;
            RedisDbconn.Instance.AddInt("TeamOfferApplyId");
            RedisDbconn.Instance.ReleaseLock(LockKey);
            return TeamOfferApplyId;
        }
        #endregion


         #region 生成商家进件资料Id
        public static int MakeMerchantAddInfoId()
        {
            string LockKey = "MakeMerchantAddInfoId";
            RedisDbconn.Instance.GetLock(LockKey);
            int MerchantAddInfoId = RedisDbconn.Instance.Get<int>("MerchantAddInfoId");
            if(MerchantAddInfoId == 0) MerchantAddInfoId = 1;
            RedisDbconn.Instance.AddInt("MerchantAddInfoId");
            RedisDbconn.Instance.ReleaseLock(LockKey);
            return MerchantAddInfoId;
        }
        #endregion


        #region 生成收款二维码Id
        public static int MakeMerchantQrCodeId()
        {
            string LockKey = "MakeMerchantQrCodeId";
            RedisDbconn.Instance.GetLock(LockKey);            
            int MerchantQrCodeId = RedisDbconn.Instance.Get<int>("MerchantQrCodeId");
            if(MerchantQrCodeId == 0) MerchantQrCodeId = 1;
            RedisDbconn.Instance.AddInt("MerchantQrCodeId");
            RedisDbconn.Instance.ReleaseLock(LockKey);
            return MerchantQrCodeId;
        }
        #endregion

        #region 生成音箱码Id
        public static int MakeMachineId()
        {
            string LockKey = "MakeMachineId";
            RedisDbconn.Instance.GetLock(LockKey);            
            int MachineId = RedisDbconn.Instance.Get<int>("MachineId");
            if(MachineId == 0) MachineId = 1;
            RedisDbconn.Instance.AddInt("MachineId");
            RedisDbconn.Instance.ReleaseLock(LockKey);
            return MachineId;
        }
        #endregion






        #region 根据ParentNav获取顶级创客Id
        public static int GetTopUserId(string ParentNav)
        {
            int TopUserId = 0;
            if (!string.IsNullOrEmpty(ParentNav))
            {
                TopUserId = int.Parse(ParentNav.Trim(',').Replace(",,", ",").Split(',')[0]);
            }
            return TopUserId;
        }
        #endregion

        #region 隐藏身份证号

        public static string HideCertId(string str)
        {
            return str.Substring(0, 3) + "***********" + str.Substring(14);
        }

        #endregion

        #region 隐藏姓名

        public static string HideRealName(string str)
        {
            string result = "";
            for (int i = 0; i < str.Length; i++)
            {
                if (i == 0)
                {
                    result += str.Substring(i, 1);
                }
                else
                { 
                    result += "*";
                }
            }
            return result;
        }

        #endregion

        #region 姓名脱敏
        /// <summary>
        /// 姓名敏感处理
        /// </summary>
        /// <param name="fullName">姓名</param>
        /// <returns>脱敏后的姓名</returns>
        public static string SetSensitiveName(string fullName)
        {
            if (string.IsNullOrEmpty(fullName)) return string.Empty;
            string familyName = fullName.Substring(0, 1);
            string end = fullName.Substring(fullName.Length - 1, 1);
            string name = string.Empty;
            //长度为2
            if (fullName.Length <= 2) name = familyName + "*";
            //长度⼤于2
            else if (fullName.Length >= 3)
            {
                name = familyName.PadRight(fullName.Length - 1, '*') + end;
            }
            return name;
        }
        #endregion


    }
}