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.Models.Main2;
using MySystem.Service.Main2;
using LitJson;
using Library;

namespace MySystem.Areas.Api.Controllers.v1.Main2
{
    [Area("Api")]
    [Route("/v1/QrCodePlateMain/[controller]/[action]")]
    public class MerchantDepositBackController : BaseController
    {
        public MerchantDepositBackController(IHttpContextAccessor accessor) : base(accessor)
        {
        }

        #region 商户激活-银联商户服务费退还结果导入
        [Authorize]
        public JsonResult UnionPayBatchImport(string value)
        {
            value = PublicFunction.DesDecrypt(value);
            JsonData data = JsonMapper.ToObject(value);
            AppResultJson result = UnionPayBatchImportDo(value);
            return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
        }
        private AppResultJson UnionPayBatchImportDo(string value)
        {
            JsonData data = JsonMapper.ToObject(value);
            string OrderNo = data["OrderNo"].ToString(); //订单号
            string Status = data["Status"].ToString(); //结果(1 成功 2 失败)
            string Remark = data["Remark"].ToString(); //备注
            Dictionary<string, object> Obj = new Dictionary<string, object>();
            MerchantDepositBack query = new MerchantDepositBack();
            Dictionary<string, object> fields = new Dictionary<string, object>();
        //     MerchantDepositBackService.Edit(fields, Id, false);

            return new AppResultJson() { Status = "1", Info = "", Data = Obj };
        }
        #endregion



        #region 商户激活-银联批量导出
        [Authorize]
        public JsonResult UnionPayBatchExport(string value)
        {
            value = PublicFunction.DesDecrypt(value);
            JsonData data = JsonMapper.ToObject(value);
            AppResultJson result = UnionPayBatchExportDo(value);
            return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
        }
        private AppResultJson UnionPayBatchExportDo(string value)
        {
            JsonData data = JsonMapper.ToObject(value);
            string Id = data["Id"].ToString(); //记录Id(多个Id用数组传参)
            Dictionary<string, object> Obj = new Dictionary<string, object>();
            MerchantDepositBack query = new MerchantDepositBack();
            Dictionary<string, object> fields = new Dictionary<string, object>();
        //     MerchantDepositBackService.Edit(fields, Id, false);

            return new AppResultJson() { Status = "1", Info = "", Data = Obj };
        }
        #endregion



        #region 商户激活-银联达标商户服务费退还记录
        [Authorize]
        public JsonResult UnionPayMerchantDepositBack(string value)
        {
            value = PublicFunction.DesDecrypt(value);
            JsonData data = JsonMapper.ToObject(value);
            List<Dictionary<string, object>> dataList = UnionPayMerchantDepositBackDo(value);
            return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
        }
        private List<Dictionary<string, object>> UnionPayMerchantDepositBackDo(string value)
        {
            JsonData data = JsonMapper.ToObject(value);
            string MerchantName = data["MerchantName"].ToString(); //商户名称
            string MctNo = data["MctNo"].ToString(); //商户号
            string CreateDate = data["CreateDate"].ToString(); //申请时间
            string ReturnWay = data["ReturnWay"].ToString(); //退还方式
            string AlipayAccountNo = data["AlipayAccountNo"].ToString(); //支付宝账号
            string BankCardNo = data["BankCardNo"].ToString(); //银行卡号
            string Status = data["Status"].ToString(); //状态(0 待处理 1 成功 2 失败 99 处理中)
            int pageSize = int.Parse(function.CheckInt(data["page_size"].ToString()));
            int pageNum = int.Parse(function.CheckInt(data["page_num"].ToString()));
            string condition = "";
            List<RelationData> relationData = new List<RelationData>();
            List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
            List<Dictionary<string, object>> source = MerchantDepositBackService.List(relationData, condition, pageNum, pageSize);
            foreach (Dictionary<string, object> subdata in source)
            {
                Dictionary<string, object> curData = new Dictionary<string, object>();
                curData.Add("Id", subdata["Id"].ToString()); //Id
                curData.Add("MerchantName", ""); //商户名称
                curData.Add("MctNo", ""); //商户号
                curData.Add("CreateDate", ""); //申请时间
                curData.Add("ReturnWay", ""); //退还方式
                curData.Add("AlipayAccountNo", ""); //支付宝账号
                curData.Add("BankCardNo", ""); //银行卡号
                curData.Add("Status", ""); //状态(0 待处理 1 成功 2 失败 99 处理中)

                dataList.Add(curData);
            }
            return dataList;
        }
        #endregion



    }
}
