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
{
    [Area("Api")]
    [Route("/v1/QrCodePlateMain/[controller]/[action]")]
    public class ConsumerOrdersController : BaseController
    {
        public ConsumerOrdersController(IHttpContextAccessor accessor) : base(accessor)
        {
        }

        #region 交易查询-银联商户交易列表
        [Authorize]
        public JsonResult UnionPayConsumerOrdersList(string value)
        {
            value = PublicFunction.DesDecrypt(value); ;
            JsonData data = JsonMapper.ToObject(value);
            List<Dictionary<string, object>> dataList = UnionPayConsumerOrdersListDo(value);
            return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
        }
        private List<Dictionary<string, object>> UnionPayConsumerOrdersListDo(string value)
        {
            JsonData data = JsonMapper.ToObject(value);
            string MerchantName = data["MerchantName"].ToString(); //商户名称
            string MakerCode = data["MakerCode"].ToString(); //创客编号
            string CreateDate = data["CreateDate"].ToString(); //交易时间
            string PayMode = data["PayMode"].ToString(); //交易平台(1 支付宝 2 微信)
            string IsAct = data["IsAct"].ToString(); //是否参与分账(0 否 1 是)
            string Status = data["Status"].ToString(); //交易状态
            string SubjectType = data["SubjectType"].ToString(); //主体类型(1 企业 2 个体 3 小微)
            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 = ConsumerOrdersService.List(relationData, condition, pageNum, pageSize);
            foreach (Dictionary<string, object> subdata in source)
            {
                Dictionary<string, object> curData = new Dictionary<string, object>();
                curData.Add("MerchantName", ""); //交易商户
                curData.Add("PayMoney", ""); //交易金额
                curData.Add("Status", ""); //交易状态
                curData.Add("PayMode", ""); //交易平台(1 支付宝 2 微信)
                curData.Add("OrderNo", ""); //交易号
                curData.Add("CreateDate", ""); //交易时间
                curData.Add("MaxDivi", ""); //分账金额
                curData.Add("SubjectType", ""); //主体类型(1 企业 2 个体 3 小微)

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



        #region 交易查询-银联订单查询分账
        [Authorize]
        public JsonResult UnionPayQueryDivideAccounts(string value)
        {
            value = PublicFunction.DesDecrypt(value); ;
            JsonData data = JsonMapper.ToObject(value);
            List<Dictionary<string, object>> dataList = UnionPayQueryDivideAccountsDo(value);
            return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
        }
        private List<Dictionary<string, object>> UnionPayQueryDivideAccountsDo(string value)
        {
            JsonData data = JsonMapper.ToObject(value);
            string Id = data["Id"].ToString(); //订单Id
            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 = ConsumerOrdersService.List(relationData, condition, pageNum, pageSize);
            foreach (Dictionary<string, object> subdata in source)
            {
                Dictionary<string, object> curData = new Dictionary<string, object>();

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



    }
}
