using Library;
using MySystem.Service.Main2;
using System.Collections.Generic;
using MySystem.Service.KxsMain;
namespace MySystem.Service.Main2
{
    /// <summary>
    /// 银联商户表工具类
    /// </summary>
    public class MerchantInfoUtil
    {
        #region 通过创客编号查询商户Id
        /// <summary>
        /// 通过创客编号查询商户Id
        /// </summary>
        /// <param name="MakerCode">创客编号</param>
        /// <returns></returns>
        public static string QueryMerchantIdByMakerCode(string MakerCode)
        {
            var info = "";
            var userInfo = UsersService.QueryByMakerCode(MakerCode);
            if (userInfo.Id > 0)
            {
                List<RelationData> relationData = new List<RelationData>();
                var merInfo = MerchantInfoService.List(relationData, " and UserId=" + userInfo.Id + "", 1, 9999);
                var merIds = "";
                foreach (Dictionary<string, object> dic in merInfo)
                {
                    var MerchantId = int.Parse(dic["Id"].ToString());
                    merIds += MerchantId + ",";
                }
                info = merIds.TrimEnd(',');
            }
            else
            {
                return "创客编号" + MakerCode + "不存在";
            }
            return info;
        }
        #endregion

        #region 通过主体类型查询商户Id
        /// <summary>
        /// 通过主体类型查询商户Id
        /// </summary>
        /// <param name="SubjectType">主体类型</param>
        /// <returns></returns>
        public static string QueryMerchantIdBySubjectType(string SubjectType)
        {
            var info = "";
            List<RelationData> relationData = new List<RelationData>();
            var merAddInfo = MerchantAddInfoService.List(relationData," and SubjectType='" + SubjectType + "'",1,999999);
            if (merAddInfo.Count > 0)
            {
                var merIds = "";
                foreach (Dictionary<string, object> dic in merAddInfo)
                {
                    var MerchantId = int.Parse(dic["Id"].ToString());
                    merIds += MerchantId + ",";
                }
                info = merIds.TrimEnd(',');
            }
            return info;
        }
        #endregion

        #region 获取已提交商户Id
        /// <summary>
        /// 获取已提交商户Id
        /// </summary>
        /// <returns></returns>
        public static string QuerySenedMerchantId()
        {
            var info = "";
            List<RelationData> relationData = new List<RelationData>();
            var merInfo = MerchantInfoService.List(relationData, " and Sort=1", 1, 9999999);
            if (merInfo.Count > 0)
            {
                var merIds = "";
                foreach (Dictionary<string, object> dic in merInfo)
                {
                    var MerchantId = int.Parse(dic["Id"].ToString());
                    merIds += MerchantId + ",";
                }
                info = merIds.TrimEnd(',');
            }
            return info;
        }
        #endregion


        #region 获取某一方已通过的商户Id
        /// <summary>
        /// 获取某一方已通过的商户Id
        /// </summary>
        /// <returns></returns>
        public static string QueryAnyIsOkMerchantId()
        {
            var info = "";
            List<RelationData> relationData = new List<RelationData>();
            var merInfo = MerchantInfoService.List(relationData, " and (Status=2 or QueryCount=2)", 1, 9999999);
            if (merInfo.Count > 0)
            {
                var merIds = "";
                foreach (Dictionary<string, object> dic in merInfo)
                {
                    var MerchantId = int.Parse(dic["Id"].ToString());
                    merIds += MerchantId + ",";
                }
                info = merIds.TrimEnd(',');
            }
            return info;
        }
        #endregion

        #region 获取是否激活商户Id
        /// <summary>
        /// 获取是否激活商户Id
        /// </summary>
        /// <param name="IsAct">激活状态(0 未激活 1 已激活)</param>
        /// <returns></returns>
        public static string QueryIsActMerchantId(int IsAct)
        {
            var info = "";
            List<RelationData> relationData = new List<RelationData>();
            var merInfo = MerchantInfoService.List(relationData, " and IsAct=" + IsAct + "", 1, 9999999);
            if (merInfo.Count > 0)
            {
                var merIds = "";
                foreach (Dictionary<string, object> dic in merInfo)
                {
                    var MerchantId = int.Parse(dic["Id"].ToString());
                    merIds += MerchantId + ",";
                }
                info = merIds.TrimEnd(',');
            }
            return info;
        }
        #endregion

        #region 获取指定时间段激活商户Id
        /// <summary>
        /// 获取指定时间段激活商户Id
        /// </summary>
        /// <param name="StartDate">开始时间</param>
        /// <param name="EndDate">结束时间</param>
        /// <returns></returns>
        public static string QueryActDateMerchantId(string StartDate,string EndDate)
        {
            var info = "";
            List<RelationData> relationData = new List<RelationData>();
            var merInfo = MerchantInfoService.List(relationData, " and UpdateDate>='" + StartDate + " 00:00:00' and UpdateDate<='" + EndDate + " 23:59:59'", 1, 9999999);
            if (merInfo.Count > 0)
            {
                var merIds = "";
                foreach (Dictionary<string, object> dic in merInfo)
                {
                    var MerchantId = int.Parse(dic["MerchantId"].ToString());
                    merIds += MerchantId + ",";
                }
                info = merIds.TrimEnd(',');
            }
            return info;
        }
        #endregion

        #region 主体类型
        /// <summary>
        /// 主体类型
        /// </summary>
        /// <returns></returns>
        public static Dictionary<string, string> GetSubjects()
        {
            Dictionary<string, string> dic = new Dictionary<string, string>();
            dic.Add("SUBJECT_TYPE_INDIVIDUAL", "个体工商户");
            dic.Add("SUBJECT_TYPE_ENTERPRISE", "企业公司");
            dic.Add("SUBJECT_TYPE_SMALL", "小微商户");
            // dic.Add("SUBJECT_TYPE_INSTITUTIONS", "党政、机关及事业单位");
            // dic.Add("SUBJECT_TYPE_OTHERS", "其他组织");
            return dic;
        }
        #endregion

        #region 账户类型
        /// <summary>
        /// 账户类型
        /// </summary>
        /// <returns></returns>
        public static Dictionary<string, string> GetAccountTypes()
        {
            Dictionary<string, string> dic = new Dictionary<string, string>();
            dic.Add("BANK_ACCOUNT_TYPE_CORPORATE", "企业对公银行账号");
            dic.Add("BANK_ACCOUNT_TYPE_PERSONAL", "法人个人银行卡");
            return dic;
        }
        #endregion

        #region 获取字典参数
        /// <summary>
        /// 获取字典参数
        /// </summary>
        /// <param name="dic"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string GetDicValue(Dictionary<string, string> dic, string key)
        {
            key = function.CheckNull(key);
            if (dic.ContainsKey(key))
            {
                return dic[key];
            }
            return "";
        }
        #endregion

    }
}