using MySystem.Models.Main;
using Library;
using MySystem.Service.Main;
using System.Collections.Generic;
namespace MySystem
{
    /// <summary>
    /// 商户服务费退还记录工具类
    /// </summary>
    public class MerchantDepositBackUtil
    {

        #region 商户激活—商户服务费退还
        /// <summary>
        /// 商户激活—商户服务费退还
        /// </summary>
        /// <param name="MerchantId">商户Id</param>
        /// <param name="ReturnWay">退还方式</param>
        /// <param name="MobileCode">短信验证码</param>
        /// <param name="ReturnNo">退还账号</param>
        /// <returns></returns>
        public static string AddMerchantDepositBackDo(int MerchantId, int ReturnWay, string MobileCode, string ReturnNo)
        {
            var query = MerchantAddInfoService.Query(MerchantId);
            MobileCodeCheck mobilecheck = RedisDbconn.Instance.Get<MobileCodeCheck>("MobileCodeCheck:" + query.ServicePhone);
            if (mobilecheck == null)
            {
                return "短信验证码不正确";
            }
            if (mobilecheck.CheckCode != MobileCode)
            {
                return "短信验证码不正确";
            }
            string checks = RedisDbconn.Instance.Get<string>("MerchantDepositBack:" + MerchantId);
            if (checks == "1")
            {
                return "已申请退押，请勿重复申请";
            }
            RedisDbconn.Instance.Clear("MobileCodeCheck:" + query.ServicePhone);
            Dictionary<string, object> Obj = new Dictionary<string, object>();
            RedisDbconn.Instance.Set("MerchantDepositBack:" + MerchantId, "1");
            RedisDbconn.Instance.SetExpire("MerchantDepositBack:" + MerchantId, 10);
            Dictionary<string, object> fields = new Dictionary<string, object>();
            fields.Add("MerchantId", MerchantId); //商户Id
            fields.Add("ReturnWay", ReturnWay); //退还方式
            AppResultJson resultJson = MerchantDepositBackService.Add(fields);
            return "success";
        }
        #endregion

    }
}