using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.AspNetCore.Authorization;

using System.Web;
using MySystem.MainModels;
using LitJson;
using Library;

namespace MySystem.Areas.Api.Controllers.v1
{
    [Area("Api")]
    [Route("Api/v1/[controller]/[action]")]
    public class MerchantAddInfoController : BaseController
    {
        public MerchantAddInfoController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
        {
        }




        #region 创客-首页-新增商户
        [Authorize]
        public JsonResult Add(string value)
        {
            value = DesDecrypt(value);
            JsonData data = JsonMapper.ToObject(value);
            AppResultJson result = AddDo(value);
            return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
        }
        public AppResultJson AddDo(string value)
        {
            JsonData data = JsonMapper.ToObject(value);
            string ContactName = data["ContactName"].ToString(); //管理员姓名
            string ContactIdNumber = data["ContactIdNumber"].ToString(); //管理员身份证件号码
            string MobilePhone = data["MobilePhone"].ToString(); //联系手机
            string ContactEmail = data["ContactEmail"].ToString(); //联系邮箱
            string SubjectType = data["SubjectType"].ToString(); //主体类型
            string LicenseCopy = data["LicenseCopy"].ToString(); //营业执照照片
            string LicenseNumber = data["LicenseNumber"].ToString(); //统一社会信用代码
            string CertMerchantName = data["CertMerchantName"].ToString(); //商户名称
            string CertLegalPerson = data["CertLegalPerson"].ToString(); //法人姓名
            string IdCardCopy = data["IdCardCopy"].ToString(); //身份证人像面照片
            string IdCardNational = data["IdCardNational"].ToString(); //身份证国徽面照片
            string IdCardName = data["IdCardName"].ToString(); //身份证姓名
            string IdCardNumber = data["IdCardNumber"].ToString(); //身份证号码
            string IdCardAddress = data["IdCardAddress"].ToString(); //身份证号码
            string CardPeriodBeginString = data["CardPeriodBegin"].ToString();
            if (string.IsNullOrEmpty(CardPeriodBeginString))
            {
                CardPeriodBeginString = "1900-01-01";
            }
            DateTime CardPeriodBegin = DateTime.Parse(CardPeriodBeginString); //身份证有效期开始时间
            string CardPeriodEndString = data["CardPeriodEnd"].ToString();
            if (string.IsNullOrEmpty(CardPeriodEndString))
            {
                CardPeriodEndString = "1900-01-01";
            }
            DateTime CardPeriodEnd = DateTime.Parse(CardPeriodEndString); //身份证有效期结束时间
            string ServicePhone = data["ServicePhone"].ToString(); //客服电话
            string BizStoreName = data["BizStoreName"].ToString(); //门店名称
            string BizAddressCode = data["BizAddressCode"].ToString(); //门店省市编码
            string BizStoreAddress = data["BizStoreAddress"].ToString(); //门店地址
            string StoreEntrancePic = data["StoreEntrancePic"].ToString(); //门店门头照片
            string IndoorPic = data["IndoorPic"].ToString(); //店内环境照片
            string QualificationType = data["QualificationType"].ToString(); //所属行业
            string SettlementId = data["SettlementId"].ToString(); //入驻结算规则ID
            string AlipayMccCode = "";
            if (!string.IsNullOrEmpty(SettlementId))
            {
                AlipayMccCode = SettlementId.Substring(SettlementId.IndexOf("_") + 1);
                SettlementId = SettlementId.Substring(0, SettlementId.IndexOf("_"));
            }
            string AlipayAccount = data["AlipayAccount"].ToString(); //支付宝账号
            string BankAccountType = data["BankAccountType"].ToString(); //账户类型
            string AccountName = data["AccountName"].ToString(); //开户名称
            string AccountBank = data["AccountBank"].ToString(); //开户银行
            string BankAddressCode = data["BankAddressCode"].ToString(); //开户银行省市编码
            string MerchantShortname = data["MerchantShortname"].ToString();
            string BankName = data["BankName"].ToString(); //开户银行全称
            string AccountNumber = data["AccountNumber"].ToString(); //银行账号
            string Qualifications = data["Qualifications"].ToString(); //特殊资质图
            int Finish = int.Parse(function.CheckInt(data["Finish"].ToString()));
            int UserId = int.Parse(function.CheckInt(data["UserId"].ToString()));
            int MerchantAddInfoId = int.Parse(function.CheckInt(data["Id"].ToString()));
            string BankBranchId = "";
            if (Finish == 1)
            {
                OpenBankTable openBank = maindb.OpenBankTable.FirstOrDefault(m => m.BankName == BankName);
                if (openBank == null)
                {
                    return new AppResultJson() { Status = "-1", Info = "开户银行全称不正确" };
                }
                BankBranchId = openBank.BankCode;
            }
            Dictionary<string, object> Obj = new Dictionary<string, object>();
            MerchantAddInfo query = maindb.MerchantAddInfo.FirstOrDefault(m => m.CertMerchantName == CertMerchantName);
            if (query == null)
            {
                query = maindb.MerchantAddInfo.Add(new MerchantAddInfo()
                {
                    CreateDate = DateTime.Now,
                    CertMerchantName = CertMerchantName,
                }).Entity;
                maindb.SaveChanges();
            }
            query.UpdateDate = DateTime.Now; //修改时间
            query.ContactName = ContactName; //管理员姓名
            query.ContactIdNumber = ContactIdNumber; //管理员身份证件号码
            query.MobilePhone = MobilePhone; //联系手机
            query.ContactEmail = ContactEmail; //联系邮箱
            query.SubjectType = SubjectType; //主体类型
            query.LicenseCopy = LicenseCopy; //营业执照照片
            query.LicenseNumber = LicenseNumber; //统一社会信用代码
            query.LegalPerson = CertLegalPerson; //;体户经营者/法人姓名
            query.CertMerchantName = CertMerchantName; //商户名称
            query.CertLegalPerson = CertLegalPerson; //法人姓名
            query.ServicePhone = ServicePhone; //客服电话
            query.BizStoreName = BizStoreName; //门店名称
            query.BizAddressCode = BizAddressCode; //门店省市编码
            query.BizStoreAddress = BizStoreAddress; //门店地址
            query.StoreEntrancePic = StoreEntrancePic; //门店门头照片
            query.IndoorPic = IndoorPic; //店内环境照片
            query.QualificationType = QualificationType; //所属行业
            query.SettlementId = SettlementId; //入驻结算规则ID
            query.BankAccountType = BankAccountType; //账户类型
            query.AccountName = AccountName; //开户名称
            query.AccountBank = AccountBank; //开户银行
            query.BankAddressCode = BankAddressCode; //开户银行省市编码
            query.BankName = BankName; //开户银行全称
            query.BankBranchId = BankBranchId;
            query.AccountNumber = AccountNumber; //银行账号
            query.IdCardCopy = IdCardCopy; //身份证人像面照片
            query.IdCardNational = IdCardNational; //身份证国徽面照片
            query.IdCardName = IdCardName; //身份证姓名
            query.IdCardNumber = IdCardNumber; //身份证号码
            query.IdCardAddress = IdCardAddress; //身份证居住地址
            query.CardPeriodBegin = CardPeriodBegin; //身份证有效期开始时间
            query.CardPeriodEnd = CardPeriodEnd; //身份证有效期结束时间
            query.MerchantShortname = MerchantShortname;
            query.Qualifications = Qualifications; //特殊资质图片
            query.ActivitiesId = "20191030111cff5b5e";
            query.ActivitiesRate = "0.38";
            query.CreateMan = AlipayAccount;
            query.UpdateMan = AlipayMccCode;
            MerchantInfo merchant = maindb.MerchantInfo.FirstOrDefault(m => m.Id == query.Id);
            if (merchant == null)
            {
                merchant = maindb.MerchantInfo.Add(new MerchantInfo()
                {
                    Id = query.Id,
                    CreateDate = DateTime.Now,
                }).Entity;
                maindb.SaveChanges();
            }
            merchant.UpdateDate = DateTime.Now;
            merchant.UserId = UserId; //创客
            merchant.Name = CertMerchantName;
            merchant.Mobile = MobilePhone;
            merchant.Areas = BizAddressCode;
            merchant.Address = BizStoreAddress;
            if (Finish == 1)
            {
                merchant.Sort = 1;
                // 如果提交完整资料，则发送到BsServer执行进件操作
                RedisDbconn.Instance.AddList("MerchantConfirmQueue", "{\"MerchantId\":\"" + merchant.Id + "\"}");
            }
            maindb.SaveChanges();
            Obj.Add("Id", MerchantAddInfoId); //Id
            return new AppResultJson() { Status = "1", Info = "", Data = Obj };
        }
        #endregion


        #region 创客-首页-商户进件详情
        // [Authorize]
        public JsonResult Detail(string value)
        {
            value = DesDecrypt(value);
            JsonData data = JsonMapper.ToObject(value);
            Dictionary<string, object> Obj = DetailDo(value);
            return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
        }
        public Dictionary<string, object> DetailDo(string value)
        {
            JsonData data = JsonMapper.ToObject(value);
            Dictionary<string, object> Obj = new Dictionary<string, object>();
            int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
            Dictionary<string, string> Subjects = GetSubjects();
            Dictionary<string, string> AccountTypes = GetAccountTypes();
            MerchantAddInfo query = MerchantAddInfoDbconn.Instance.Get(Id) ?? new MerchantAddInfo();
            List<SettleData> Settles = GetSettles(query.SubjectType);
            Obj.Add("ContactName", query.ContactName); //管理员姓名
            Obj.Add("ContactIdNumber", query.ContactIdNumber); //管理员身份证件号码
            Obj.Add("OpenId", query.OpenId); //管理员微信openid
            Obj.Add("MobilePhone", query.MobilePhone); //联系手机
            Obj.Add("ContactEmail", query.ContactEmail); //联系邮箱
            Obj.Add("SubjectType", query.SubjectType); //主体类型
            if (Subjects.ContainsKey(function.CheckNull(query.SubjectType)))
            {
                Obj.Add("SubjectTypeName", Subjects[function.CheckNull(query.SubjectType)]);
            }
            else
            {
                Obj.Add("SubjectTypeName", "");
            }
            Obj.Add("LicenseCopy", query.LicenseCopy); //营业执照照片
            Obj.Add("LicenseNumber", query.LicenseNumber); //统一社会信用代码
            Obj.Add("LegalPerson", query.LegalPerson); //个体户经营者/法人姓名
            Obj.Add("CertCopy", query.CertCopy); //登记证书照片
            Obj.Add("CertType", query.CertType); //登记证书类型
            Obj.Add("CertNumber", query.CertNumber); //证书号
            Obj.Add("CertMerchantName", query.CertMerchantName); //商户名称
            Obj.Add("CompanyAddress", query.CompanyAddress); //注册地址
            Obj.Add("CertLegalPerson", query.CertLegalPerson); //法人姓名
            Obj.Add("PeriodBegin", query.PeriodBegin == null ? "" : query.PeriodBegin.Value.ToString("yyyy-MM-dd HH:mm:ss")); //有效期限开始日期
            Obj.Add("PeriodEnd", query.PeriodEnd == null ? "" : query.PeriodEnd.Value.ToString("yyyy-MM-dd HH:mm:ss")); //有效期限结束日期
            Obj.Add("OrganizationCopy", query.OrganizationCopy); //组织机构代码证照片
            Obj.Add("OrganizationCode", query.OrganizationCode); //组织机构代码
            Obj.Add("OrgPeriodBegin", query.OrgPeriodBegin == null ? "" : query.OrgPeriodBegin.Value.ToString("yyyy-MM-dd HH:mm:ss")); //组织机构代码证有效期开始日期
            Obj.Add("OrgPeriodEnd", query.OrgPeriodEnd == null ? "" : query.OrgPeriodEnd.Value.ToString("yyyy-MM-dd HH:mm:ss")); //组织机构代码证有效期结束日期
            Obj.Add("CertificateLetterCopy", query.CertificateLetterCopy); //单位证明函照片
            Obj.Add("IdDocType", query.IdDocType); //证件类型
            Obj.Add("Owner", query.Owner); //经营者/法人是否为受益人
            Obj.Add("UboInfoIdType", query.UboInfoIdType); //最终受益人证件类型
            Obj.Add("UboInfoIdCardCopy", query.UboInfoIdCardCopy); //最终受益人身份证人像面照片
            Obj.Add("UboInfoIdCardNational", query.UboInfoIdCardNational); //身份证国徽面照片
            Obj.Add("UboInfoIdDocCopy", query.UboInfoIdDocCopy); //最终受益人证件照片
            Obj.Add("UboInfoName", query.UboInfoName); //受益人姓名
            Obj.Add("UboInfoIdNumber", query.UboInfoIdNumber); //最终受益人证件号码
            Obj.Add("UboInfoIdPeriodBegin", query.UboInfoIdPeriodBegin == null ? "" : query.UboInfoIdPeriodBegin.Value.ToString("yyyy-MM-dd HH:mm:ss")); //证件有效期开始时间
            Obj.Add("UboInfoIdPeriodEnd", query.UboInfoIdPeriodEnd == null ? "" : query.UboInfoIdPeriodEnd.Value.ToString("yyyy-MM-dd HH:mm:ss")); //证件有效期结束时间
            Obj.Add("MerchantShortname", query.MerchantShortname); //商户简称
            Obj.Add("ServicePhone", query.ServicePhone); //客服电话
            Obj.Add("SalesScenesType", query.SalesScenesType); //经营场景类型
            Obj.Add("BizStoreName", query.BizStoreName); //门店名称
            Obj.Add("BizAddressCode", query.BizAddressCode); //门店省市编码
            Obj.Add("BizStoreAddress", query.BizStoreAddress); //门店地址
            Obj.Add("StoreEntrancePic", query.StoreEntrancePic); //门店门头照片
            Obj.Add("IndoorPic", query.IndoorPic); //店内环境照片
            Obj.Add("BizSubAppid", query.BizSubAppid); //线下场所对应的商家APPID
            Obj.Add("MpAppid", query.MpAppid); //服务商公众号APPID
            Obj.Add("MpSubAppid", query.MpSubAppid); //商家公众号APPID
            Obj.Add("MpPics", query.MpPics); //公众号页面截图
            Obj.Add("MiniProgramAppid", query.MiniProgramAppid); //服务商小程序APPID
            Obj.Add("MiniProgramSubAppid", query.MiniProgramSubAppid); //商家小程序APPID
            Obj.Add("MiniProgramPics", query.MiniProgramPics); //小程序截图
            Obj.Add("AppAppid", query.AppAppid); //服务商应用APPID
            Obj.Add("AppSubAppid", query.AppSubAppid); //商家应用APPID
            Obj.Add("AppPics", query.AppPics); //APP截图
            Obj.Add("WebDomain", query.WebDomain); //互联网网站域名
            Obj.Add("WebAuthorisation", query.WebAuthorisation); //网站授权函
            Obj.Add("WebAppId", query.WebAppId); //互联网网站对应的商家APPID
            Obj.Add("SubCorpId", query.SubCorpId); //商家企业微信CorpID
            Obj.Add("WeworkPics", query.WeworkPics); //企业微信页面截图
            Obj.Add("SettlementId", query.SettlementId + "_" + query.UpdateMan); //入驻结算规则ID
            Obj.Add("QualificationType", query.QualificationType); //所属行业
            SettleData item = Settles.FirstOrDefault(m => m.value == query.QualificationType);
            if (item != null)
            {
                Obj.Add("QualificationTypeName", item.ptext + "," + item.text);
            }
            else
            {
                Obj.Add("QualificationTypeName", "");
            }
            Obj.Add("Qualifications", query.Qualifications); //特殊资质图片
            Obj.Add("ActivitiesId", query.ActivitiesId); //优惠费率活动ID
            Obj.Add("ActivitiesRate", query.ActivitiesRate); //优惠费率活动值
            Obj.Add("BankAccountType", query.BankAccountType); //账户类型
            if (AccountTypes.ContainsKey(function.CheckNull(query.BankAccountType)))
            {
                Obj.Add("BankAccountTypeName", AccountTypes[function.CheckNull(query.BankAccountType)]);
            }
            else
            {
                Obj.Add("BankAccountTypeName", "");
            }
            Obj.Add("AccountName", query.AccountName); //开户名称
            Obj.Add("AccountBank", query.AccountBank); //开户银行
            Obj.Add("BankAddressCode", query.BankAddressCode); //开户银行省市编码
            Obj.Add("BankBranchId", query.BankBranchId); //开户银行联行号
            Obj.Add("BankName", query.BankName); //开户银行全称
            Obj.Add("AccountNumber", query.AccountNumber); //银行账号
            Obj.Add("ApplymentId", query.ApplymentId); //微信支付申请单号
            Obj.Add("SubMchid", query.SubMchid); //特约商户号
            Obj.Add("SignUrl", query.SignUrl); //超级管理员签约链接
            Obj.Add("ApplymentState", query.ApplymentState); //申请单状态
            Obj.Add("AuditDetail", query.AuditDetail); //驳回原因详情
            Obj.Add("IdCardCopy", query.IdCardCopy); //身份证人像面照片
            Obj.Add("IdCardNational", query.IdCardNational); //身份证国徽面照片
            Obj.Add("IdCardName", query.IdCardName); //身份证姓名
            Obj.Add("IdCardNumber", query.IdCardNumber); //身份证号码
            Obj.Add("IdCardAddress", query.IdCardAddress);
            Obj.Add("CardPeriodBegin", query.CardPeriodBegin == null ? "" : query.CardPeriodBegin.Value.ToString("yyyy-MM-dd HH:mm:ss")); //身份证有效期开始时间
            Obj.Add("CardPeriodEnd", query.CardPeriodEnd == null ? "" : query.CardPeriodEnd.Value.ToString("yyyy-MM-dd HH:mm:ss")); //身份证有效期结束时间
            Obj.Add("Id", query.Id); //Id
            Obj.Add("Status", query.Status); //状态
            Obj.Add("CreateDate", query.CreateDate); //创建时间
            Obj.Add("AlipayAccount", query.CreateMan); //支付宝账号
            return Obj;
        }
        #endregion


        #region 创客-首页-进件选项接口
        [Authorize]
        public JsonResult Options(string value)
        {
            value = DesDecrypt(value);
            JsonData data = JsonMapper.ToObject(value);
            List<Dictionary<string, object>> dataList = OptionsDo(value);
            return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
        }
        public List<Dictionary<string, object>> OptionsDo(string value)
        {
            JsonData data = JsonMapper.ToObject(value);
            string Kind = data["Kind"].ToString(); //分类
            int PageSize = int.Parse(function.CheckInt(data["PageSize"].ToString()));
            int PageNum = int.Parse(function.CheckInt(data["PageNum"].ToString()));
            List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
            if (Kind == "2")
            {
                dataList = GetPersonSettles();
            }
            else if (Kind == "21")
            {
                dataList = GetBusinessSettles();
            }
            else
            {
                Dictionary<string, string> query = new Dictionary<string, string>();
                if (Kind == "1")
                {
                    query = GetSubjects();
                }
                else if (Kind == "3")
                {
                    query = GetAccountTypes();
                }
                else if (Kind == "4")
                {
                    query = GetBanks();
                }
                foreach (string key in query.Keys)
                {
                    Dictionary<string, object> curData = new Dictionary<string, object>();
                    curData.Add("text", query[key]); //文本
                    curData.Add("value", key); //值
                    dataList.Add(curData);
                }
            }
            return dataList;
        }
        public 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_INSTITUTIONS", "党政、机关及事业单位");
            // dic.Add("SUBJECT_TYPE_OTHERS", "其他组织");
            return dic;
        }
        public List<SettleData> GetSettles(string Kind)
        {
            if (Kind == "SUBJECT_TYPE_INDIVIDUAL")
            {
                return GetPersonSettleItems();
            }
            return GetBusinessSettleItems();
        }

        public List<SettleData> GetPersonSettleItems()
        {
            List<SettleData> dic = new List<SettleData>();
            dic.Add(new SettleData() { ptext = "食品生鲜", text = "肉、禽、蛋及水产品等", value = "719", code = "A0002_B0202" });
            dic.Add(new SettleData() { ptext = "健身运动服务", text = "健身房", value = "719", code = "A0004_B0064" });
            dic.Add(new SettleData() { ptext = "健身运动服务", text = "体育场馆", value = "719", code = "A0004_B0068" });
            dic.Add(new SettleData() { ptext = "居民生活服务", text = "公共交通", value = "719", code = "A0006_B0088" });
            dic.Add(new SettleData() { ptext = "景区/酒店", text = "旅行住宿", value = "719", code = "A0010_B0157" });
            dic.Add(new SettleData() { ptext = "居民生活服务", text = "生活服务", value = "719", code = "A0003_B0116" });
            dic.Add(new SettleData() { ptext = "零售", text = "百货商城", value = "719", code = "A0002_B0017" });
            dic.Add(new SettleData() { ptext = "服饰鞋包", text = "服饰鞋包", value = "719", code = "A0002_B0026" });
            dic.Add(new SettleData() { ptext = "零售", text = "家居家纺建材", value = "719", code = "A0002_B0216" });
            dic.Add(new SettleData() { ptext = "零售", text = "母婴玩具", value = "719", code = "A0002_B0032" });
            dic.Add(new SettleData() { ptext = "零售", text = "数码家电", value = "719", code = "A0003_B0051" });
            dic.Add(new SettleData() { ptext = "零售", text = "图书音像", value = "719", code = "A0002_B0031" });
            dic.Add(new SettleData() { ptext = "居民生活服务", text = "文化玩乐宠物", value = "719", code = "A0004_B0070" });
            dic.Add(new SettleData() { ptext = "咨询/娱乐票务", text = "娱乐票务", value = "719", code = "A0004_B0065" });
            dic.Add(new SettleData() { ptext = "零售", text = "办公用品", value = "719", code = "A0002_B0203" });
            dic.Add(new SettleData() { ptext = "零售", text = "工业产品", value = "719", code = "A0002_B0042" });
            dic.Add(new SettleData() { ptext = "咨询/娱乐票务", text = "专业咨询", value = "719", code = "A0008_B0139" });
            dic.Add(new SettleData() { ptext = "其他", text = "其他类别", value = "716", code = "A0002_B0043" });


            // dic.Add(new SettleData() { ptext = "餐饮", text = "餐饮", code = "C_C05_5814", value = "719", special = 0});
            // dic.Add(new SettleData() { ptext = "食品生鲜", text = "酒类", code = "C_C05_5921", value = "719", special = 1});
            // dic.Add(new SettleData() { ptext = "食品生鲜", text = "肉、禽、蛋及水产品等", code = "C_C05_5422", value = "719", special = 0});
            // dic.Add(new SettleData() { ptext = "私立/民营医院/诊所", text = "医疗服务", code = "P_P01_8011", value = "719", special = 1});
            // dic.Add(new SettleData() { ptext = "保健器械/医疗器械/非处方药品", text = "药品、药品经营者（批发商）", code = "B_B04_5122", value = "719", special = 1});
            // dic.Add(new SettleData() { ptext = "保健器械/医疗器械/非处方药品", text = "医疗器械", code = "B_B04_5047", value = "719", special = 1});
            // dic.Add(new SettleData() { ptext = "游艺厅/KTV/网吧", text = "游艺厅/KTV", code = "D_D01_7999", value = "719", special = 1});
            // dic.Add(new SettleData() { ptext = "游艺厅/KTV/网吧", text = "网吧", code = "D_D01_7999", value = "719", special = 1});
            // dic.Add(new SettleData() { ptext = "宠物医院", text = "宠物及宠物用品", code = "C_C10_5995", value = "719", special = 1});
            // dic.Add(new SettleData() { ptext = "零售批发/生活娱乐/其他", text = "公共交通", code = "A_A01_4121", value = "719", special = 0});
            // dic.Add(new SettleData() { ptext = "零售批发/生活娱乐/其他", text = "旅行住宿", code = "A_A04_7011", value = "719", special = 0});
            // dic.Add(new SettleData() { ptext = "零售批发/生活娱乐/其他", text = "公共仓储、集装整理", code = "A_A02_4225", value = "719", special = 0});
            // dic.Add(new SettleData() { ptext = "零售批发/生活娱乐/其他", text = "商业服务", code = "S_S05_7338", value = "719", special = 0});
            // dic.Add(new SettleData() { ptext = "零售批发/生活娱乐/其他", text = "汽车租赁和服务", code = "S_S10_7512", value = "719", special = 0});
            // dic.Add(new SettleData() { ptext = "零售批发/生活娱乐/其他", text = "生活服务", code = "S_S08_7295", value = "719", special = 0});
            // dic.Add(new SettleData() { ptext = "零售批发/生活娱乐/其他", text = "百货商城", code = "C_C04_5411", value = "719", special = 0});
            // dic.Add(new SettleData() { ptext = "零售批发/生活娱乐/其他", text = "服饰鞋包", code = "C_C06_5699", value = "719", special = 0});
            // dic.Add(new SettleData() { ptext = "零售批发/生活娱乐/其他", text = "家居家纺建材", code = "C_C03_5211", value = "719", special = 0});
            // dic.Add(new SettleData() { ptext = "零售批发/生活娱乐/其他", text = "母婴玩具", code = "C_C02_5641", value = "719", special = 0});
            // dic.Add(new SettleData() { ptext = "零售批发/生活娱乐/其他", text = "数码家电", code = "C_C07_5732", value = "719", special = 0});
            // dic.Add(new SettleData() { ptext = "零售批发/生活娱乐/其他", text = "图书音像", code = "C_C09_5942", value = "719", special = 0});
            // dic.Add(new SettleData() { ptext = "零售批发/生活娱乐/其他", text = "文化玩乐宠物", code = "C_C10_5995", value = "719", special = 0});
            // dic.Add(new SettleData() { ptext = "零售批发/生活娱乐/其他", text = "彩票", code = "D_D03_7995", value = "719", special = 0});
            // dic.Add(new SettleData() { ptext = "零售批发/生活娱乐/其他", text = "娱乐票务", code = "D_D01_7999", value = "719", special = 0});
            // dic.Add(new SettleData() { ptext = "零售批发/生活娱乐/其他", text = "法律咨询和律师事务所", code = "P_P04_8111", value = "719", special = 1});
            // dic.Add(new SettleData() { ptext = "零售批发/生活娱乐/其他", text = "办公用品", code = "B_B01_5943", value = "719", special = 0});
            // dic.Add(new SettleData() { ptext = "零售批发/生活娱乐/其他", text = "工业产品", code = "B_B02_5065", value = "719", special = 0});
            // dic.Add(new SettleData() { ptext = "零售批发/生活娱乐/其他", text = "汽车和运输工具", code = "B_B03_5599", value = "719", special = 0});
            // dic.Add(new SettleData() { ptext = "零售批发/生活娱乐/其他", text = "专业咨询", code = "P_P04_8999", value = "719", special = 0});
            // dic.Add(new SettleData() { ptext = "话费通讯", text = "话费充值与缴费", code = "D_D04_4815", value = "720", special = 1});
            // dic.Add(new SettleData() { ptext = "加油", text = "加油站、服务站", code = "B_B03_5541", value = "721", special = 1});
            return dic;
        }
        public List<Dictionary<string, object>> GetPersonSettles()
        {
            List<SettleData> dic = GetPersonSettleItems();

            int i = 0;
            List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
            foreach (string sub in dic.Select(m => m.ptext).Distinct().ToList())
            {
                i += 1;
                Dictionary<string, object> bigDic = new Dictionary<string, object>();
                bigDic.Add("value", i.ToString());
                bigDic.Add("text", sub);
                List<Dictionary<string, object>> children = new List<Dictionary<string, object>>();
                foreach (SettleData ssub in dic.Where(m => m.ptext == sub).ToList())
                {
                    Dictionary<string, object> smallDic = new Dictionary<string, object>();
                    smallDic.Add("value", ssub.value + "_" + ssub.code);
                    smallDic.Add("text", ssub.text);
                    smallDic.Add("special", ssub.special);
                    children.Add(smallDic);
                }
                bigDic.Add("children", children);
                list.Add(bigDic);
            }

            return list;
        }
        public List<SettleData> GetBusinessSettleItems()
        {
            List<SettleData> dic = new List<SettleData>();
            dic.Add(new SettleData() { ptext = "餐饮", text = "餐饮", value = "716", code = "A0001_B0001" });
            dic.Add(new SettleData() { ptext = "食品生鲜", text = "肉、禽、蛋及水产品等", value = "716", code = "A0002_B0202" });
            dic.Add(new SettleData() { ptext = "健身运动服务", text = "健身房", value = "716", code = "A0004_B0064" });
            dic.Add(new SettleData() { ptext = "健身运动服务", text = "体育场馆", value = "716", code = "A0004_B0068" });
            dic.Add(new SettleData() { ptext = "城市公共交通", text = "公共交通", value = "716", code = "A0006_B0088" });
            dic.Add(new SettleData() { ptext = "景区/酒店", text = "旅行住宿", value = "716", code = "A0010_B0157" });
            dic.Add(new SettleData() { ptext = "居民生活服务", text = "生活服务", value = "716", code = "A0003_B0116" });
            dic.Add(new SettleData() { ptext = "零售", text = "百货商城", value = "716", code = "A0002_B0017" });
            dic.Add(new SettleData() { ptext = "服饰鞋包", text = "服饰鞋包", value = "716", code = "A0002_B0026" });
            dic.Add(new SettleData() { ptext = "零售", text = "家居家纺建材", value = "716", code = "A0002_B0216" });
            dic.Add(new SettleData() { ptext = "零售", text = "母婴玩具", value = "716", code = "A0002_B0032" });
            dic.Add(new SettleData() { ptext = "零售", text = "数码家电", value = "716", code = "A0003_B0051" });
            dic.Add(new SettleData() { ptext = "零售", text = "图书音像", value = "716", code = "A0002_B0031" });
            dic.Add(new SettleData() { ptext = "居民生活服务", text = "文化玩乐宠物", value = "716", code = "A0004_B0070" });
            dic.Add(new SettleData() { ptext = "咨询/娱乐票务", text = "娱乐票务", value = "716", code = "A0004_B0065" });
            dic.Add(new SettleData() { ptext = "零售", text = "办公用品", value = "716", code = "A0002_B0203" });
            dic.Add(new SettleData() { ptext = "零售", text = "工业产品", value = "716", code = "A0002_B0042" });
            dic.Add(new SettleData() { ptext = "婚介平台/就业信息平台/其他信息服务平台", text = "婚介服务", value = "720", code = "A0003_B0053" });
            dic.Add(new SettleData() { ptext = "零售", text = "其它类别", value = "716", code = "A0002_B0043" });


            // dic.Add(new SettleData() { ptext = "餐饮", text = "餐饮", code = "C_C05_5814", value = "716", special = 0});
            // dic.Add(new SettleData() { ptext = "电商平台", text = "电商平台", code = "C_C05_5814", value = "716", special = 0});
            // dic.Add(new SettleData() { ptext = "食品生鲜", text = "酒类", code = "C_C05_5921", value = "716", special = 1});
            // dic.Add(new SettleData() { ptext = "食品生鲜", text = "肉、禽、蛋及水产品等", code = "C_C05_5422", value = "716", special = 0});
            // dic.Add(new SettleData() { ptext = "电信运营商/宽带收费", text = "电信通讯", code = "D_D04_4814", value = "716", special = 1});
            // dic.Add(new SettleData() { ptext = "私立/民营医院/诊所", text = "医疗服务", code = "P_P01_8011", value = "716", special = 1});
            // dic.Add(new SettleData() { ptext = "保健器械/医疗器械/非处方药品", text = "医疗器械", code = "B_B04_5047", value = "716", special = 1});
            // dic.Add(new SettleData() { ptext = "保健器械/医疗器械/非处方药品", text = "药品、药品经营者（批发商）", code = "B_B04_5122", value = "716", special = 1});
            // dic.Add(new SettleData() { ptext = "游艺厅/KTV/网吧", text = "游艺厅/KTV", code = "D_D01_7999", value = "716", special = 1});
            // dic.Add(new SettleData() { ptext = "游艺厅/KTV/网吧", text = "网吧", code = "D_D01_7999", value = "716", special = 1});
            // dic.Add(new SettleData() { ptext = "宠物医院", text = "宠物及宠物用品", code = "C_C10_5995", value = "716", special = 1});
            // dic.Add(new SettleData() { ptext = "旅行社", text = "旅行社和旅游服务", code = "A_A04_4722", value = "716", special = 1});
            // dic.Add(new SettleData() { ptext = "宗教组织", text = "宗教物品", code = "C_C10_5973", value = "716", special = 0});
            // dic.Add(new SettleData() { ptext = "宗教组织", text = "其他宗教服务", code = "P_P04_8999", value = "716", special = 1});
            // dic.Add(new SettleData() { ptext = "文物经营/文物复制品销售", text = "文物经营/文物复制品销售", code = "C_C10_5971", value = "716", special = 1});
            // dic.Add(new SettleData() { ptext = "拍卖典当", text = "典当行", code = "S_S04_5933", value = "716", special = 1});
            // dic.Add(new SettleData() { ptext = "零售批发/生活娱乐/网上商城/其他", text = "公共交通", code = "A_A01_4121", value = "716", special = 0});
            // dic.Add(new SettleData() { ptext = "零售批发/生活娱乐/网上商城/其他", text = "旅行住宿", code = "A_A04_7011", value = "716", special = 0});
            // dic.Add(new SettleData() { ptext = "零售批发/生活娱乐/网上商城/其他", text = "公共仓储、集装整理", code = "A_A02_4225", value = "716", special = 0});
            // dic.Add(new SettleData() { ptext = "零售批发/生活娱乐/网上商城/其他", text = "商业服务", code = "S_S05_7338", value = "716", special = 0});
            // dic.Add(new SettleData() { ptext = "零售批发/生活娱乐/网上商城/其他", text = "汽车租赁和服务", code = "S_S10_7512", value = "716", special = 0});
            // dic.Add(new SettleData() { ptext = "零售批发/生活娱乐/网上商城/其他", text = "生活服务", code = "S_S08_7295", value = "716", special = 0});
            // dic.Add(new SettleData() { ptext = "零售批发/生活娱乐/网上商城/其他", text = "百货商城", code = "C_C04_5411", value = "716", special = 0});
            // dic.Add(new SettleData() { ptext = "零售批发/生活娱乐/网上商城/其他", text = "服饰鞋包", code = "C_C06_5699", value = "716", special = 0});
            // dic.Add(new SettleData() { ptext = "零售批发/生活娱乐/网上商城/其他", text = "家居家纺建材", code = "C_C03_5211", value = "716", special = 0});
            // dic.Add(new SettleData() { ptext = "零售批发/生活娱乐/网上商城/其他", text = "母婴玩具", code = "C_C02_5641", value = "716", special = 0});
            // dic.Add(new SettleData() { ptext = "零售批发/生活娱乐/网上商城/其他", text = "数码家电", code = "C_C07_5732", value = "716", special = 0});
            // dic.Add(new SettleData() { ptext = "零售批发/生活娱乐/网上商城/其他", text = "图书音像", code = "C_C09_5942", value = "716", special = 0});
            // dic.Add(new SettleData() { ptext = "零售批发/生活娱乐/网上商城/其他", text = "文化玩乐宠物", code = "C_C10_5995", value = "716", special = 0});
            // dic.Add(new SettleData() { ptext = "零售批发/生活娱乐/网上商城/其他", text = "彩票", code = "D_D03_7995", value = "716", special = 0});
            // dic.Add(new SettleData() { ptext = "零售批发/生活娱乐/网上商城/其他", text = "娱乐票务", code = "D_D01_7999", value = "716", special = 0});
            // dic.Add(new SettleData() { ptext = "零售批发/生活娱乐/网上商城/其他", text = "法律咨询和律师事务所", code = "P_P04_8111", value = "716", special = 1});
            // dic.Add(new SettleData() { ptext = "零售批发/生活娱乐/网上商城/其他", text = "办公用品", code = "B_B01_5943", value = "716", special = 0});
            // dic.Add(new SettleData() { ptext = "零售批发/生活娱乐/网上商城/其他", text = "工业产品", code = "B_B02_5065", value = "716", special = 0});
            // dic.Add(new SettleData() { ptext = "零售批发/生活娱乐/网上商城/其他", text = "汽车和运输工具", code = "B_B03_5599", value = "716", special = 0});
            // dic.Add(new SettleData() { ptext = "零售批发/生活娱乐/网上商城/其他", text = "专业咨询", code = "P_P04_8999", value = "716", special = 0});
            // dic.Add(new SettleData() { ptext = "话费通讯", text = "话费充值与缴费", code = "D_D04_4815", value = "728", special = 1});
            // dic.Add(new SettleData() { ptext = "婚介平台/就业信息平台/其他", text = "婚介服务", code = "S_S08_7273", value = "728", special = 0});
            // dic.Add(new SettleData() { ptext = "门户论坛/网络广告及推广/软件开发/其他互联网服务", text = "计算机服务/其他", code = "D_D05_7372", value = "711", special = 0});
            // dic.Add(new SettleData() { ptext = "快递", text = "快递服务", code = "A_A02_4215", value = "717", special = 1});
            // dic.Add(new SettleData() { ptext = "加油", text = "加油站、服务站", code = "B_B03_5541", value = "717", special = 1});
            // dic.Add(new SettleData() { ptext = "公共事业（水电煤气）", text = "公共事业（电、气、水）", code = "S_S06_4900", value = "730", special = 1});
            // dic.Add(new SettleData() { ptext = "公共事业（水电煤气）", text = "公共事业-电力缴费", code = "S_S06_4901", value = "730", special = 1});
            // dic.Add(new SettleData() { ptext = "公共事业（水电煤气）", text = "公共事业-煤气缴费", code = "S_S06_4902", value = "730", special = 1});
            // dic.Add(new SettleData() { ptext = "公共事业（水电煤气）", text = "公共事业-自来水缴费", code = "S_S06_4903", value = "730", special = 1});
            return dic;
        }
        public List<Dictionary<string, object>> GetBusinessSettles()
        {
            List<SettleData> dic = GetBusinessSettleItems();

            int i = 0;
            List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
            foreach (string sub in dic.Select(m => m.ptext).Distinct().ToList())
            {
                i += 1;
                Dictionary<string, object> bigDic = new Dictionary<string, object>();
                bigDic.Add("value", i.ToString());
                bigDic.Add("text", sub);
                List<Dictionary<string, object>> children = new List<Dictionary<string, object>>();
                foreach (SettleData ssub in dic.Where(m => m.ptext == sub).ToList())
                {
                    Dictionary<string, object> smallDic = new Dictionary<string, object>();
                    smallDic.Add("value", ssub.value + "_" + ssub.code);
                    smallDic.Add("text", ssub.text);
                    smallDic.Add("special", ssub.special);
                    children.Add(smallDic);
                }
                bigDic.Add("children", children);
                list.Add(bigDic);
            }

            return list;
        }
        public 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;
        }
        public Dictionary<string, string> GetBanks()
        {
            Dictionary<string, string> dic = new Dictionary<string, string>();
            dic.Add("工商银行", "工商银行");
            dic.Add("农业银行", "农业银行");
            dic.Add("邮储银行", "邮储银行");
            dic.Add("建设银行", "建设银行");
            dic.Add("招商银行", "招商银行");
            dic.Add("中国银行", "中国银行");
            dic.Add("交通银行", "交通银行");
            dic.Add("浦发银行", "浦发银行");
            dic.Add("广发银行", "广发银行");
            dic.Add("民生银行", "民生银行");
            dic.Add("平安银行", "平安银行");
            dic.Add("光大银行", "光大银行");
            dic.Add("兴业银行", "兴业银行");
            dic.Add("中信银行", "中信银行");
            dic.Add("上海银行", "上海银行");
            dic.Add("其他银行", "其他银行");
            return dic;
        }
        #endregion


        #region 桥接mpap2
        public JsonResult businessscope(string value)
        {
            return Json(new AppResultJson());
        }
        #endregion






        #region 检查签名是否合法，合法返回1，不合法返回提示信息

        /// <summary>
        /// 检查签名是否合法，合法返回1，不合法返回提示信息
        /// </summary>
        /// <param name="value">请求的参数(json字符串)</param>
        /// <param name="signField">要签名的字段</param>
        /// <returns></returns>
        private string CheckSign(string value, string[] signField)
        {
            JsonData json = JsonMapper.ToObject(value);
            Dictionary<string, string> dic = new Dictionary<string, string>();
            for (int i = 0; i < signField.Length; i++)
            {
                dic.Add(signField[i], json[signField[i]].ToString());
            }
            string sign = json["sign"].ToString(); //客户端签名字符串
            return new Sign().sign(dic, sign);
        }

        #endregion

    }
}
