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.Main1;
using MySystem.Service.Main1;
using LitJson;
using Library;
using MySystem.Service.KxsMain;

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

        #region 重置交易额-直连重置创客个人交易额
        [Authorize]
        public JsonResult DirectResetUserPersonalAmount(string value)
        {
            value = PublicFunction.DesDecrypt(value); ;
            JsonData data = JsonMapper.ToObject(value);
            AppResultJson result = DirectResetUserPersonalAmountDo(value);
            return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
        }
        private AppResultJson DirectResetUserPersonalAmountDo(string value)
        {
            JsonData data = JsonMapper.ToObject(value);
            string MakerCode = data["MakerCode"].ToString(); //创客编号
            string TradeDate = data["TradeDate"].ToString(); //交易时间
            if (string.IsNullOrEmpty(data["MakerCode"].ToString()) || string.IsNullOrEmpty(data["TradeDate"].ToString()))
            {
                return new AppResultJson() { Status = "-1", Info = "创客编号和交易时间不能为空" };
            }
            var user = UsersService.QueryByMakerCode(MakerCode);
            if (user.Id == 0)
            {
                return new AppResultJson() { Status = "-1", Info = "未找到" + MakerCode + "相关信息" };
            }
            string[] datelist = TradeDate.Split(new string[] { " - " }, StringSplitOptions.None);
            string start = DateTime.Parse(datelist[0]).ToString("yyyyMMdd");
            string end = DateTime.Parse(datelist[1]).ToString("yyyyMMdd");
            string info = "{\"UserId\":\"" + user.Id + "\",\"StartDate\":\"" + start + "\",\"EndDate\": \"" + end + "\"}";
            RedisDbconn.Instance.AddList("ResetUserSelfStatDataQueue", info);
            Dictionary<string, object> Obj = new Dictionary<string, object>();

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


        #region 重置交易额-银联重置创客个人交易额
        [Authorize]
        public JsonResult UnionPayResetUserPersonalAmount(string value)
        {
            value = PublicFunction.DesDecrypt(value); ;
            JsonData data = JsonMapper.ToObject(value);
            AppResultJson result = UnionPayResetUserPersonalAmountDo(value);
            return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
        }
        private AppResultJson UnionPayResetUserPersonalAmountDo(string value)
        {
            JsonData data = JsonMapper.ToObject(value);
            string MakerCode = data["MakerCode"].ToString(); //创客编号
            string TradeDate = data["TradeDate"].ToString(); //交易时间
            if (string.IsNullOrEmpty(data["MakerCode"].ToString()) || string.IsNullOrEmpty(data["TradeDate"].ToString()))
            {
                return new AppResultJson() { Status = "-1", Info = "创客编号和交易时间不能为空" };
            }
            var user = UsersService.QueryByMakerCode(MakerCode);
            if (user.Id == 0)
            {
                return new AppResultJson() { Status = "-1", Info = "未找到" + MakerCode + "相关信息" };
            }
            string[] datelist = TradeDate.Split(new string[] { " - " }, StringSplitOptions.None);
            string start = DateTime.Parse(datelist[0]).ToString("yyyyMMdd");
            string end = DateTime.Parse(datelist[1]).ToString("yyyyMMdd");
            string info = "{\"UserId\":\"" + user.Id + "\",\"StartDate\":\"" + start + "\",\"EndDate\": \"" + end + "\"}";
            RedisDbconn.Instance.AddList("ResetUserSelfStatDataQueue2", info);
            Dictionary<string, object> Obj = new Dictionary<string, object>();

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


        #region 重置交易额-直连重置创客团队交易额
        [Authorize]
        public JsonResult DirectResetUserTeamAmount(string value)
        {
            value = PublicFunction.DesDecrypt(value); ;
            JsonData data = JsonMapper.ToObject(value);
            AppResultJson result = DirectResetUserTeamAmountDo(value);
            return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
        }
        private AppResultJson DirectResetUserTeamAmountDo(string value)
        {
            JsonData data = JsonMapper.ToObject(value);
            string MakerCode = data["MakerCode"].ToString(); //创客编号
            string TradeDate = data["TradeDate"].ToString(); //交易时间
            if (string.IsNullOrEmpty(data["MakerCode"].ToString()) || string.IsNullOrEmpty(data["TradeDate"].ToString()))
            {
                return new AppResultJson() { Status = "-1", Info = "创客编号和交易时间不能为空" };
            }
            var user = UsersService.QueryByMakerCode(MakerCode);
            if (user.Id == 0)
            {
                return new AppResultJson() { Status = "-1", Info = "未找到" + MakerCode + "相关信息" };
            }
            string[] datelist = TradeDate.Split(new string[] { " - " }, StringSplitOptions.None);
            string start = DateTime.Parse(datelist[0]).ToString("yyyyMMdd");
            string end = DateTime.Parse(datelist[1]).ToString("yyyyMMdd");
            string info = "{\"UserId\":\"" + user.Id + "\",\"StartDate\":\"" + start + "\",\"EndDate\": \"" + end + "\"}";
            RedisDbconn.Instance.AddList("ResetUserTeamStatDataQueue", info);
            Dictionary<string, object> Obj = new Dictionary<string, object>();

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


        #region 重置交易额-银联重置创客团队交易额
        [Authorize]
        public JsonResult UnionPayResetUserTeamAmount(string value)
        {
            value = PublicFunction.DesDecrypt(value); ;
            JsonData data = JsonMapper.ToObject(value);
            AppResultJson result = UnionPayResetUserTeamAmountDo(value);
            return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
        }
        private AppResultJson UnionPayResetUserTeamAmountDo(string value)
        {
            JsonData data = JsonMapper.ToObject(value);
            string MakerCode = data["MakerCode"].ToString(); //创客编号
            string TradeDate = data["TradeDate"].ToString(); //交易时间
            if (string.IsNullOrEmpty(data["MakerCode"].ToString()) || string.IsNullOrEmpty(data["TradeDate"].ToString()))
            {
                return new AppResultJson() { Status = "-1", Info = "创客编号和交易时间不能为空" };
            }
            var user = UsersService.QueryByMakerCode(MakerCode);
            if (user.Id == 0)
            {
                return new AppResultJson() { Status = "-1", Info = "未找到" + MakerCode + "相关信息" };
            }
            string[] datelist = TradeDate.Split(new string[] { " - " }, StringSplitOptions.None);
            string start = DateTime.Parse(datelist[0]).ToString("yyyyMMdd");
            string end = DateTime.Parse(datelist[1]).ToString("yyyyMMdd");
            string info = "{\"UserId\":\"" + user.Id + "\",\"StartDate\":\"" + start + "\",\"EndDate\": \"" + end + "\"}";
            RedisDbconn.Instance.AddList("ResetUserTeamStatDataQueue2", info);
            Dictionary<string, object> Obj = new Dictionary<string, object>();

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


    }
}
